vega-frontend-monorepo/libs/react-helpers/src/hooks/use-navigator-online.ts
Matthew Russell cb9b811730
feat(#1791): block height check (#2701)
Co-authored-by: asiaznik <artur@vegaprotocol.io>
2023-01-27 11:31:23 +01:00

17 lines
477 B
TypeScript

import { useSyncExternalStore } from 'react';
const subscribe = (onStoreChange: () => void) => {
window.addEventListener('online', onStoreChange);
window.addEventListener('offline', onStoreChange);
return () => {
window.removeEventListener('online', onStoreChange);
window.removeEventListener('offline', onStoreChange);
};
};
export const useNavigatorOnline = () =>
useSyncExternalStore(
subscribe,
() => window.navigator.onLine,
() => true
);