Skip to content

Instantly share code, notes, and snippets.

@Tim-W-James
Created February 12, 2023 07:04
Show Gist options
  • Select an option

  • Save Tim-W-James/4899ef04fd636ccbbbe30d4632c98bbd to your computer and use it in GitHub Desktop.

Select an option

Save Tim-W-James/4899ef04fd636ccbbbe30d4632c98bbd to your computer and use it in GitHub Desktop.
React useOnlineStatus Custom Hook #hooks
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