react-fns – Browser APIs turned into declarative React components and HOCs

react-fns is a collection of imperative Browser API’s turned into declarative React components and higher-order components for lots of common situations.

The <Network /> component for example is a wrapper around the Network Information API.

import { Network } from 'react-fns';

const Example = () => (
  <Network
    render={({ online, offlineAt }) => (
      <div>
        {online ? 'Online!' : 'Offline'}
        {offlineAt && `Last connected ${offlineAt.toISOString()}`}
      </div>
    )}
  />
);

export default Example;

Next to using this component and its render prop, an alternative using an HOC withNetwork is also available.

Other supported APIs include DeviceMotion, DeviceOrientation, GeoPosition, Windows Scroll Offset, etc.

react-fns – Browser APIs turned into declarative React components and HOCs →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.