Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created February 2, 2020 18:39
Show Gist options
  • Save jsmanifest/73442aed8187f7c534ab083e8d3215a6 to your computer and use it in GitHub Desktop.
Save jsmanifest/73442aed8187f7c534ab083e8d3215a6 to your computer and use it in GitHub Desktop.
import { toast } from 'react-toastify'
import {
info as toastInfo,
success as toastSuccess,
toastIds,
} from 'util/toast'
const onOnline = () => {
if (toast.isActive(toastIds.internetOffline)) {
toast.dismiss(toastIds.internetOffline)
}
if (toast.isActive(toastIds.retryInternet)) {
toast.dismiss(toastIds.retryInternet)
}
if (!toast.isActive(toastIds.internetOnline)) {
toastSuccess('You are now reconnected to the internet.', {
position: 'bottom-center',
toastId: toastIds.internetOnline,
})
}
}
const onOffline = () => {
if (!toast.isActive(toastIds.internetOffline)) {
toastInfo('You are disconnected from the internet right now.', {
position: 'bottom-center',
autoClose: false,
toastId: toastIds.internetOffline,
})
}
}
useInternet({ onOnline, onOffline })
return <App />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment