In React
const compA = ()=>{
const [loading,setLoading]=useState(false);
useEffect(()=>{
const blaBla="nothing";
return ()=>{
console.log("Component unmounted");
setLoading(false)
}
},[])
const handleSubmit=()=>{
setLoading(true)
window.location.href="//google.com";
}
return (
<button onClick={handleSubmit} disabled={loading}>Link</button>
)
}
This useEffect cleanup function will not fire when the user clicked on the button to open google.com
The question is how to get this cleanup work to do execute the setLoading(false)
code when user navigate to external pages, so when the user click on the browser back button the button will be enabled again?
I need to clear/reset component state when the user navigate to external links