-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(better reconnect): check online status and reconnect when we com…
…e back online
- Loading branch information
1 parent
00141d1
commit a67a3ef
Showing
10 changed files
with
87 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
const useIsOnline = (): boolean | undefined => { | ||
if (typeof window === "undefined" || typeof navigator === "undefined") { | ||
return; | ||
} | ||
|
||
const [isOnline, setOnlineStatus] = useState(window.navigator.onLine); | ||
|
||
useEffect(() => { | ||
const toggleOnlineStatus = () => setOnlineStatus(window.navigator.onLine); | ||
|
||
window.addEventListener("online", toggleOnlineStatus); | ||
window.addEventListener("offline", toggleOnlineStatus); | ||
|
||
return () => { | ||
window.removeEventListener("online", toggleOnlineStatus); | ||
window.removeEventListener("offline", toggleOnlineStatus); | ||
}; | ||
}, [isOnline]); | ||
|
||
return isOnline; | ||
}; | ||
|
||
export { useIsOnline }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters