Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(network-status): detect initial network status
Browse files Browse the repository at this point in the history
  • Loading branch information
alessioprestileo committed Jun 6, 2020
1 parent 452015a commit 9b52ec6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/network-status/useNetworkStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { useState, useEffect } from 'react'
import { NetworkStatus } from './types'

export const useNetworkStatus = (): NetworkStatus => {
const isOnline = navigator.onLine
const [networkStatus, setNetworkStatus] = useState({
isOnline: true,
wasOffline: false,
isOnline,
wasOffline: !isOnline,
})
const handleOnline = () => {
setNetworkStatus((prevState) => ({ ...prevState, isOnline: true }))
Expand Down

0 comments on commit 9b52ec6

Please sign in to comment.