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
2016-09-02 15:32:10 -07:00

44 lines
884 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;