Last active
September 23, 2023 04:33
-
-
Save tarsusi/e07101816f7115aea0943de5a4398e33 to your computer and use it in GitHub Desktop.
useOnlineStatus
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
| import { useState } from "react" | |
| import useEventListener from "../useEventListener/useEventListener" | |
| export default function 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