Skip to content

Instantly share code, notes, and snippets.

@tarsusi
Last active September 23, 2023 04:33
Show Gist options
  • Select an option

  • Save tarsusi/e07101816f7115aea0943de5a4398e33 to your computer and use it in GitHub Desktop.

Select an option

Save tarsusi/e07101816f7115aea0943de5a4398e33 to your computer and use it in GitHub Desktop.
useOnlineStatus
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