React higher-order component for detecting network offline state
JavaScript HTML Shell
Latest commit ab8085b Sep 12, 2017 @LINKIWI committed on GitHub Merge pull request #6 from LINKIWI/greenkeeper/babel-eslint-8.0.0
Update babel-eslint to the latest version


npm version Build Status Coverage Status

react-offline-hoc is a React higher-order component factory to enhance your existing components with an isOnline prop that indicates the online/offline status of the application.

This HOC uses the browser's native window.navigator.onLine property and its online/offline events to determine the current offline state.



A true value for the isOnline prop indicates that the client has an active connection to the network. Disconnecting from the network (desktop) or enabling airplane mode (mobile) will change isOnline to false.

import React from 'react';
import withOfflineState from 'react-offline-hoc';

const MyComponent = ({ isOnline }) => (
    Connectivity is currently: {isOnline ? 'online' : 'offline'}

export default withOfflineState(MyComponent);

Accessing the wrapped component

The wrapped component's ref is available via a class property component on the HOC instance.

import React, { Component } from 'react';
import withOfflineState from 'react-offline-hoc';

class MyComponent extends Component {
  method() {

  render() {

const wrapped = withOfflineState(MyComponent);


A simple application that uses react-offline-hoc is provided in the example/ directory. To run it:

$ cd example/
$ npm install
$ npm run start
# Local server available at localhost:8080

Try connecting and disconnecting from the network and observe the resulting behavior.