useEffect can see setState changes code example
Example: how to setstate in useeffect
React.useEffect(() => {
let didCancel = false;
// ...
// you can check didCancel
// before running any setState
// ...
return () => {
didCancel = true;
};
});