2.0.3 • Published 2 years ago

@beskar-labs/use-online v2.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

useOnline

useOnline is a tiny, zero-dependency, SSR-friendly hook for responding to online / offline changes. It's a React hook that returns a boolean indicating whether the browser is online or not. Specifically, it's a neat little listener that combines navigator.onLine with window event listeners. Since we can't listen to updates on window variables, pairing this with the event listener for each scenario appears to work.

Installation

yarn add @beskar-labs/use-online

Usage

import useOnline from '@beskar-labs/use-online';

const App = () => {
  const isOnline = useOnline();

  return (
    <div>
      <h1>useOnline</h1>
      <p>{isOnline ? 'You are online' : 'You are offline'}</p>
    </div>
  );
};
2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago