This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/frontend/components/Offline/Offline.js
Tom Moor 2095b3a874 Fix prettier integration, format (#31)
* Fix prettier integration, format

* Reformat again
2017-04-27 21:48:13 -07:00

44 lines
887 B
JavaScript

import React from 'react';
class Offline extends React.Component {
static propTypes = {
children: React.PropTypes.node,
};
static childContextTypes = {
offline: React.PropTypes.bool,
};
state = {
offline: !navigator.onLine,
};
getChildContext() {
return {
offline: this.state.offline,
};
}
componentDidMount = () => {
window.addEventListener('offline', this.handleConnectionState);
window.addEventListener('online', this.handleConnectionState);
};
componentWillUnmount = () => {
window.removeEventListener('offline', this.handleConnectionState);
window.removeEventListener('online', this.handleConnectionState);
};
handleConnectionState = () => {
this.setState({
offline: !navigator.onLine,
});
};
render() {
return React.Children.only(this.props.children);
}
}
export default Offline;