mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-08-10 16:43:19 +00:00
24 lines
818 B
TypeScript
24 lines
818 B
TypeScript
import { useEffect, useState } from 'react'
|
|
import NetInfo, { NetInfoState } from '@react-native-community/netinfo'
|
|
import {log} from '../services/logService'
|
|
|
|
|
|
export default function useIsInternetReachable() {
|
|
// useState hook for setting netInfo
|
|
// const [netInfo, setNetInfo] = useState({} as NetInfoState)
|
|
const [isInternetReachable, setIsInternetReachable] = useState<boolean>(true)
|
|
|
|
useEffect(() => {
|
|
// Whenever connection status changes below event fires
|
|
const unsubscribe = NetInfo.addEventListener((state: NetInfoState) => {
|
|
setIsInternetReachable(state.isInternetReachable as boolean)
|
|
})
|
|
// Event cleanup function
|
|
return () => {
|
|
unsubscribe()
|
|
}
|
|
}, [])
|
|
|
|
return isInternetReachable
|
|
}
|