Created
June 5, 2020 01:50
-
-
Save brianbancroft/d8ab79ce879bbb6d1e8e8ede29227c77 to your computer and use it in GitHub Desktop.
useOffline
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
const [online, setOnline] = useState(true) | |
useEffect(() => { | |
let offlineToast | |
const goOffline = () => { | |
setOnline(false) | |
} | |
const goOnline = () => { | |
setOnline(true) | |
} | |
window.addEventListener('offline', goOffline) | |
window.addEventListener('online', goOnline) | |
return () => { | |
window.removeEventListener('offline', goOffline) | |
window.removeEventListener('online', goOnline) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment