react-native-netinfo-redux

0.1.0 • Public • Published

react-native-netinfo-redux

Listen to network state changes and dispatch redux actions

Installation

npm install --save react-native-netinfo-redux

Usage

Add the enhancer when creating the store

import { createNetInfoEnhancer } from "react-native-netinfo-redux";
 
const store = createStore(reducer, initialState, compose(
  createNetInfoEnhancer(),
  ...
));

Add the networkReducer

import { netinfoReducer } from "react-native-netinfo-redux";
 
export default combineReducers(
  Object.assign({}, ..., netinfoReducer)
);

Usage with Redux Saga

Import the action name and listen to its dispatch

import { NETWORK_STATE_CHANGE } from "react-native-netinfo-redux";
 
function* onNetworkStateChange(data){
  // Do stuff here
}
 
function* watchNetworkState(){
  yield takeEvery(NETWORK_STATE_CHANGE, onNetworkStateChange);
}
 
export default function* rootSaga() {
  yield all([
    ...
    watchNetworkState()
  ]);
}

Credits

https://github.com/bamlab/redux-enhancer-react-native-appstate

Readme

Keywords

none

Package Sidebar

Install

npm i react-native-netinfo-redux

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

3.33 kB

Total Files

4

Last publish

Collaborators

  • mtumiati