Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 29, 2020 06:18
Show Gist options
  • 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