Skip to content

baptistelambert/hyperapp-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hyperapp-network

Notifies your app when the network connection goes online or offline.

Inspired by react-network.

Installation

npm install hyperapp-network
# or with yarn
yarn add hyperapp-network

Usage

import { h, app } from 'hyperapp';
import { Network } from 'hyperapp-network';

const state = {
  online: window.navigator.onLine
};

const actions = {
  updateOnline = online => state => ({ online })
};

const view = (state, actions) => (
  <main>
    <Network
      onChange={actions.updateOnline}
      online={state.online}
      render={({ online }) => <div>{online ? 'Online' : 'Offline'}</div>}
    />
  </main>
)

app(state, actions, view, document.body);