Guest User

Untitled

a guest
Feb 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. const useEventListener = () => {
  2. const onBeforeUnload = (event) => {
  3. event.returnValue = 'Changes will not be saved. This action cannot be undone'; // eslint-disable-line no-param-reassign
  4. };
  5. useEffect(() => {
  6. window.addEventListener('beforeunload', onBeforeUnload);
  7. return () => window.removeEventListener('beforeunload', onBeforeUnload);
  8. });
  9. };
  10.  
  11. const ProjectContainer = () => {
  12. // I just have to called my hook
  13. useEventListener();
  14. return (
  15. <div>Hi</div>
  16. );
  17. };
Add Comment
Please, Sign In to add comment