Created
February 12, 2023 07:04
-
-
Save Tim-W-James/4899ef04fd636ccbbbe30d4632c98bbd to your computer and use it in GitHub Desktop.
React useOnlineStatus Custom Hook #hooks
This file contains hidden or 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
| const useOnlineStatus = () => { | |
| const [online, setOnline] = useState(navigator.onLine); | |
| useEventListener("online", () => setOnline(navigator.onLine)); | |
| useEventListener("offline", () => setOnline(navigator.onLine)); | |
| return online; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment