Skip to content

Latest commit

History

History
28 lines (19 loc) 路 684 Bytes

useOnlineState.md

File metadata and controls

28 lines (19 loc) 路 684 Bytes

useOnlineState

Uses the Navigator online API to define whether the browser is connected or not.

Returns a boolean value that if is true indicates the browser is connected.

Why? 馃挕

  • You want to your component to re-render ether when the connection goes online or offline.

Basic Usage:

import useOnlineState from 'beautiful-react-hooks/useOnlineState';

const ConnectionTest = () => {
  const isOnline = useOnlineState();
      
  return (
    <DisplayDemo>
      <p>Connection status: {isOnline ? 'online' : 'offline'}</p>
    </DisplayDemo>
  );
};

<ConnectionTest />