Part of a collection of Higher-Order Components for React, especially useful with Recompose.
Dynamically map online/offline status to props using navigator.onLine
(Can I use?).
yarn add @hocs/with-online-status-props
withOnlineStatusProps(
mapStatusToProps: (onlineStatus: Object) => Object,
): HigherOrderComponent
import React from 'react';
import withOnlineStatusProps from '@hocs/with-online-status-props';
const Demo = (props) => (
<h1>props: {JSON.stringify(props)}</h1>
);
export default withOnlineStatusProps(
({ isOnline, isOffline }) => ({ isOnline, isOffline })
)(Demo);
- Target Component will be just passed through on unsupported platforms (i.e.
global.navigator.onLine
isundefined
) like with Server-Side Rendering. This means that there will be no status (i.e.undefined
) which might be expected, but you can take care of it using RecomposedefaultProps
HOC if it's really necessary.