import { useState } from 'react' ; import { useEventListener } from '../useEventListener' ; import { useMount } from '../useMount' ; see https export function useOnline ( ) { const [ online , setOnline ] = useState ( false ) ; useMount ( ( ) => { setOnline ( navigator . onLine ) ; } ) ; useEventListener ( 'offline' , ( ) => { setOnline ( false ) ; } ) ; useEventListener ( 'online' , ( ) => { setOnline ( true ) ; } ) ; return online ; }