1.0.1 • Published 2 years ago

redux-enhancer-react-native-netstate v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

redux-enhancer-react-native-netstate

Notify net state changes directly to your Redux store!

Installation

npm install --save redux-enhancer-react-native-netstate

OR

yarn add redux-enhancer-react-native-netstate

Usage

When you create your Redux store, add the enhancer:

import { createStore } from 'redux';
import applyNetStateListener from 'redux-enhancer-react-native-netstate';

...

const store = createStore(reducers, initalState, [
  applyNetStateListener(),
]);

The store will now automatically dispatch net state related actions.

For instance, you can use it in a reducer:

import { ONLINE, OFFLINE } from 'redux-enhancer-react-native-netstate';

function reducer(state = '', action) {
  switch (action.type) {
    case ONLINE:
      return 'app is online';
    case OFFLINE:
      return 'app is offline';    
    default:
      return state
  }
}