You need to clean up your timeout on unmount, otherwise, it tries to execute your hooks to update the internal state of the component after it goes out of scope (I assume functions like setLoading
and setError
are from a React hook).
To do so, put the output of setTimeout
in a variable and then call clearTimeout
in the function you return from useEffect
. That's the clean up function and it's run when the component gets unmounted. So you need something like this:
React.useEffect(() => {
...
const timeout = setTimeout(...)
return () => {
...
clearTimeout(timeout);
}
}, [])
See the docs for more info: https://reactjs.org/docs/hooks-reference.html#cleaning-up-an-effect
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…