Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 22, 2019 04:28
Show Gist options
  • Save jsmanifest/5f5f08f6241917cb54749f3cd0eb3ab9 to your computer and use it in GitHub Desktop.
Save jsmanifest/5f5f08f6241917cb54749f3cd0eb3ab9 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'
import App from './App'
const Root = () => {
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