react-redux-internet-connection
v0.1.0
Published
Check internet connection from your redux's state
Downloads
351
Maintainers
Readme
react-redux-internet-connection
Check internet connection from your redux's state
Installation
npm:
npm install react-redux-internet-connection
yarn:
yarn add react-redux-internet-connection
Config
In your main reducers
import { combineReducers } from 'redux';
import { reducer as internet } from 'react-redux-internet-connection';
const rootReducer = combineReducers({
internet
});
export default rootReducer;
And you just need to add ReactReduxInternetConnection
in App.js
import React, { PureComponent } from 'react';
import { ReactReduxInternetConnection } from 'react-redux-internet-connection';
class App extends PureComponent {
render() {
return (
<div className="App">
<h1>react-internet-connection</h1>
<ReactReduxInternetConnection />
</div>
);
}
}
export default App;
Usage
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
// you can access in every where to internet connection :)
@connect(state => ({
connection: state.internet.connection
}), { })
export default class Home extends PureComponent {
static propTypes = {
connection: PropTypes.bool,
};
render() {
const { connection } = this.props;
return (
<div>
{connection &&
<h1>connected :)</h1>}
{!connection &&
<h1>disconnected :(</h1>}
</div>
);
}
}