Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 29, 2020 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/b5388afd82c1ce1fcaad4edf0ff68fc1 to your computer and use it in GitHub Desktop.
Save velotiotech/b5388afd82c1ce1fcaad4edf0ff68fc1 to your computer and use it in GitHub Desktop.
// state
const [offline, setOffline] = React.useState(false);
// effects
React.useEffect(() => {
window.addEventListener("offline", offlineListener);
return () => {
window.removeEventListener("offline", offlineListener);
};
}, []);
{/* add to jsx */}
{offline ? (
<div className="banner-offline">The app is currently offline</div>
) : null}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment