这个错误已经在很多博客,论坛等中进行过讨论,我推测问题出在没有可取消的承诺。我想知道如何退订 蓝鸟的诺言。
useEffect(() => {
let isFetchable = !!qualifiedURL;
const fetchData = async () => {
let fetcher = Promise.resolve();
if (isFetchable && !data) {
setLoading(true);
if (method === 'GET') {
fetcher = fetch(method, qualifiedURL);
} else {
fetcher = fetch(method, qualifiedURL, {
...options,
});
}
fetcher.then((result) => {
setError(null);
setData(result);
setHook(result);
}).catch((err) => {
setData(null);
setError(parseError(err));
}).finally(() => {
setLoading(false);
});
}
return fetcher;
};
fetchData();
return () => {
isFetchable = false;
};
}, [qualifiedURL]);
错误:
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
in StepAuthorize (created by O365) react_devtools_backend.js:6:7472
r react_devtools_backend.js:6
React 5
_callee$/< useFetch.js:95
finallyHandler bluebird.js:1988
tryCatcher bluebird.js:5370
_settlePromiseFromHandler bluebird.js:3366
_settlePromise bluebird.js:3423
_settlePromise0 bluebird.js:3468
_settlePromises bluebird.js:3548
_drainQueueStep bluebird.js:145
_drainQueue bluebird.js:138
_drainQueues bluebird.js:154
drainQueues bluebird.js:67