use-before-unload
About
A React hook that uses the onbeforeunload (beforeunload) event and tracks when the user has been Refreshed or Canceled the default browser message.
It is impossible to track if the user has left the page and is not a good idea to execute code after that.
Install
npm i @garage-panda/use-before-unload
Usage
import React from "react";
import { useBeforeUnload } from "@garage-panda/use-before-unload";
function App() {
const setEnabledBeforeUnload = useBeforeUnload({
initEnable: false,
onRefresh: () => {
},
onCancel: () => {
}
});
React.useEffect(() => {
setEnabledBeforeUnload(true);
if (!sessionStorage.length) {
}
}, []);
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Support
If you like what you see, feel free to support us!
License
MIT