diff --git a/client/src/App.jsx b/client/src/App.jsx index 131894e1..ae126335 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -16,9 +16,11 @@ import { useApp } from 'src/context/AppContext'; import { useAuth } from 'context/AuthContext'; import useIsTabActive from './hooks/useIsTabActive'; import MatchFound from './pages/MatchFound'; +import { useCloseAndReloadHandle } from './hooks/useCloseHandle'; function App() { ReactGA.initialize(import.meta.env.VITE_GOOGLE_ANALYTICS); + useCloseAndReloadHandle(); const { isLoggedIn } = useAuth(); const { updateOnlineStatus, app } = useApp(); diff --git a/client/src/hooks/useCloseHandle.js b/client/src/hooks/useCloseHandle.js new file mode 100644 index 00000000..66a3715b --- /dev/null +++ b/client/src/hooks/useCloseHandle.js @@ -0,0 +1,23 @@ + + +import { useEffect } from "react" + +export const useCloseAndReloadHandle=(condition=true)=>{ + useEffect(()=>{ + const closeWindowHandler=(event)=>{ + if (condition) { + event.preventDefault(); + event.returnValue=''; + + } + + } + + window.addEventListener('beforeunload',closeWindowHandler); + + return ()=>{ + window.removeEventListener('beforeunload',closeWindowHandler) + } + + },[condition]) +} \ No newline at end of file