You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

redux-enhancer-react-native-appstate

Package Overview
Dependencies
306
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-enhancer-react-native-appstate

Connect your App State changes directly to your Redux store


Version published
Weekly downloads
930
increased by6.04%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

redux-enhancer-react-native-appstate

Connect your App State changes directly to your Redux store!

Installation

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

Usage

When you create your Redux store, add the enhancer:

import { createStore } from 'redux';
import applyAppStateListener from 'redux-enhancer-react-native-appstate';

...

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

The store will now automatically dispatch app state related actions.

For instance, you can use it in a reducer:

import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';

function reducer(state = '', action) {
  switch (action.type) {
    case FOREGROUND:
      return 'back to foreground';
    case BACKGROUND:
      return 'background';
    case INACTIVE:
      return 'inactive';
    default:
      return state
  }
}

Usage with Redux Saga

Make sure that this enhancer is applied before the saga middleware. Otherwise, your saga would not be able to intercept the actions.

// good
const store = createStore(reducers, initalState, composeEnhancers(
  applyAppStateListener(),
  applyMiddleware(sagaMiddleware)
));

// bad
const store = createStore(reducers, initalState, composeEnhancers(
  applyMiddleware(sagaMiddleware),
  applyAppStateListener()
));

Then you can define a saga like:

import { takeLatest } from 'redux-saga/effects';
import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';

function* appHasComeBackToForeground() {
  // app has come back to foreground!
}

function* watchForAppBackToForeground() {
  yield takeLatest(
    FOREGROUND,
    catchApiExceptions(appHasComeBackToForeground),
  );
}

Contributing

See our contributing guidelines

FAQs

Package last updated on 10 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc