useEffect(() => {
console.log("Effect runs");
return () => {
console.log("Cleanup runs");
};
}, []);
If window.location.reload() is called anywhere in your application, will the cleanup callback of the useEffect fire?
Typically no, the cleanup function in useEffect won’t run on window.location.reload(). Cleanup only runs when React unmounts a component or reruns the effect, but a full page reload wipes out the JS runtime before React can do anything. If you need logic before reload/close, use beforeunload instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With