'How to use window.onbeforeunload in React for showing popup for reload if the user clicks on reload
How to use window.onbeforeunload in React for showing popup for reload if the user clicks on reload.
I tried doing this it is not working
useEffect(() => {
window.addEventListener("beforeunload", handleRefresh);
return () => {
window.removeEventListener("beforeunload", handleRefresh);
};
});
Solution 1:[1]
useEffect(() => {
window.onbeforeunload(handleRefresh)
return () => {
window.onbeforeunload("null")
};
}, []);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lokesh pandey |
