Created
April 11, 2023 10:46
-
-
Save tjinlag/c9531e370a9acb211ebff7b31e9e1812 to your computer and use it in GitHub Desktop.
React Custom Hook: useOnlineStatus
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
import { useState } from "react" | |
import useEventListener from "./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