redux-rn-misc-enhancer
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

redux-rn-misc-enhancer CircleCI npm version

redux-rn-misc-enhancer is a light weight wrapper of AppState and NetInfo which connects those changes directly to your Redux store.

Installation

yarn add redux-rn-misc-enhancer

Usage

1. Enhancer

Add applyAppStateListener and applyNetInfoListener enhancers for your redux store.

import { compose, createStore } from 'redux';
import {
  applyAppStateListener,
  applyNetInfoListener,
} from 'redux-rn-misc-enhancer';
 
const enhancer = compose(
  applyAppStateListener(),
  applyNetInfoListener(),
);
const store = createStore(reducers, initialState, enhancer);
  1. Reducer

Add appStateReducer and netInfoReducer(and other stuff) to your redux reducer.

import { Action, combineReducers, Reducer } from 'redux';
import {
  AppStateInitialState,
  appStateReducer,
  AppStateState,
  NetInfoInitialState,
  netInfoReducer,
  NetInfoState,
} from 'redux-rn-misc-enhancer';
 
export interface State {
  appState: AppStateState;
  netInfo: NetInfoState;
}
 
export const initialState: State = {
  appState: AppStateInitialState,
  netInfo: NetInfoInitialState,
};
 
const appReducer: Reducer<State> = combineReducers({
  appState: appStateReducer,
  netInfo: netInfoReducer,
});
 
const rootReducer = (state: State, action: Action) => appReducer(state, action);
 
export default rootReducer;

And that's it! You can receive app state and network info changes from redux store in any React components.

For more detail check example app.

Licence

Copyright 2018 Quipper Limited.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Readme

Keywords

none

Package Sidebar

Install

npm i redux-rn-misc-enhancer

Weekly Downloads

1

Version

0.1.0

License

Apache-2.0

Unpacked Size

29.4 kB

Total Files

43

Last publish

Collaborators

  • quipper