From 60d275644e2c36420f696df51230d464dd969736 Mon Sep 17 00:00:00 2001 From: Ritwick Dey Date: Fri, 26 Jul 2019 16:48:41 +0530 Subject: [PATCH] Fixes #12 --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index b0dc8fb..20d06df 100644 --- a/src/index.js +++ b/src/index.js @@ -11,11 +11,12 @@ function getOnlineStatus() { function useOnlineStatus() { const [onlineStatus, setOnlineStatus] = useState(getOnlineStatus()); - const goOnline = () => setOnlineStatus(true); - - const goOffline = () => setOnlineStatus(false); + useEffect(() => { + const goOnline = () => setOnlineStatus(true); + const goOffline = () => setOnlineStatus(false); + window.addEventListener("online", goOnline); window.addEventListener("offline", goOffline);