From b9e6e77fe6d6036dce50d142dd13d945a6a3355e Mon Sep 17 00:00:00 2001 From: Nathaniel Rindlaub Date: Tue, 23 Jan 2024 10:46:33 -0800 Subject: [PATCH] Add logging for connection loss --- src/app/App.jsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/app/App.jsx b/src/app/App.jsx index e3211858..a1ecb094 100644 --- a/src/app/App.jsx +++ b/src/app/App.jsx @@ -106,6 +106,25 @@ const App = () => { // }); // }, [dispatch]); + // Monitor connection loss + useEffect(() => { + const handleOffline = (e) => { + const now = new Date(); + console.log(`Lost internet connection at ${now.toISOString()}`); + } + window.addEventListener('offline', handleOffline); + return () => { window.removeEventListener('offline', handleOffline) } + }, []); + + useEffect(() => { + const handleOnline = (e) => { + const now = new Date(); + console.log(`Regained internet connection at ${now.toISOString()}`); + } + window.addEventListener('online', handleOnline); + return () => { window.removeEventListener('online', handleOnline) } + }, []); + useEffect(() => { dispatch(initTracking(GA_CONFIG)); }, [ dispatch ]);