UNPKG

react-native-offline

Version:

Handy toolbelt to deal with offline mode in React Native applications. Cross-platform, provides a smooth redux integration.

16 lines (12 loc) 446 B
import { useContext } from 'react'; import NetworkContext from '../components/NetworkContext'; export default function useIsConnected(): boolean | null { const context = useContext(NetworkContext); if (!context) { throw new Error( 'useIsConnected should be used within NetworkProvider. ' + 'Make sure you are rendering a NetworkProvider at the top of your component hierarchy', ); } return context.isConnected; }