Skip to content

Instantly share code, notes, and snippets.

@TyrealGray
Last active January 15, 2018 10:45
Show Gist options
  • Save TyrealGray/6b0dcb59290a4fc80dda09382c3ce07e to your computer and use it in GitHub Desktop.
Save TyrealGray/6b0dcb59290a4fc80dda09382c3ce07e to your computer and use it in GitHub Desktop.
configure redux store

configure redux store example

import { AsyncStorage } from 'react-native';
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
import thunk from 'redux-thunk';
import { persistStore, autoRehydrate } from 'redux-persist';

import * as reducers from './reducers';

const reducer = combineReducers( reducers );

/**
 * configure redux store to persist and rehydrate.
 */
export default function configureStore( onComplete ) {

  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

  const enhancer = composeEnhancers(
    applyMiddleware( thunk ),
    autoRehydrate()
  );

  const store = createStore(
    reducer,
    {},
    enhancer
  );

  persistStore( store, {
    storage  : AsyncStorage,
    blacklist: [ 'homeNav', 'modalLayer', 'accountSettingNav', 'tabSectionNav' ],
  }, onComplete );
  return store;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment