Download src/hooks/useBeforeUnload.ts from dimag69/fadl: direct link, hf CLI and curl.
- Browser
- Download file 571 Bytes
-
https://huggingface.co/spaces/dimag69/fadl/resolve/main/src/hooks/useBeforeUnload.ts
- Command line
-
hf download hf://spaces/dimag69/fadl/src/hooks/useBeforeUnload.ts
-
curl -L -o useBeforeUnload.ts https://huggingface.co/spaces/dimag69/fadl/resolve/main/src/hooks/useBeforeUnload.ts
571 Bytes
| import { useEffect } from 'react'; | |
| const useBeforeUnload = (downloading: boolean) => { | |
| useEffect(() => { | |
| const controller = new AbortController(); | |
| const handleBeforeUnload = (event: BeforeUnloadEvent) => { | |
| if (downloading) { | |
| event.preventDefault(); | |
| event.returnValue = ''; | |
| controller.abort(); | |
| } | |
| }; | |
| window.addEventListener('beforeunload', handleBeforeUnload); | |
| return () => { | |
| window.removeEventListener('beforeunload', handleBeforeUnload); | |
| }; | |
| }, [downloading]); | |
| }; | |
| export default useBeforeUnload; | |