1 import { useEffect } from 'react';
3 import busy from '@proton/shared/lib/busy';
5 const useBeforeUnload = (message?: string | boolean) => {
11 const handleUnload = (event: BeforeUnloadEvent) => {
12 const computedMessage = message === true ? '' : message;
14 event.preventDefault();
15 event.returnValue = computedMessage;
17 return computedMessage;
19 const unregister = busy.register();
20 window.addEventListener('beforeunload', handleUnload);
23 window.removeEventListener('beforeunload', handleUnload);
28 export default useBeforeUnload;