Connection state
Detect online and offline network state.
You can see it in action here filipchalupa.cz/connection-state. Try to disconnect your device from the internet after loading the page.
Installation
npm install connection-state
Usage
import { connectionState } from 'connection-state'
const connection = connectionState()
console.log(`You are ${connection.getState()}.`)
connection.addListener((state) => {
console.log(`Your connection state has changed. You are now ${state}.`)
})
Development
- Install dependencies:
npm ci
- Run:
npm run dev