Skip to content

Instantly share code, notes, and snippets.

@benvium
Created May 31, 2016 17:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save benvium/0967337fba314c3a8b058d45f0b0f08d to your computer and use it in GitHub Desktop.
Save benvium/0967337fba314c3a8b058d45f0b0f08d to your computer and use it in GitHub Desktop.
React Native ConfigureStore including AutoRehydrate
/**
* Creates and configures the Redux Store
*/
import {createStore, applyMiddleware, compose} from 'redux';
import thunkMiddleware from 'redux-thunk'; // useful for networking actions
import createLogger from 'redux-logger'; // log out each action
import {persistStore, autoRehydrate} from 'redux-persist';
import rootReducer from './reducers'; // this combines all reducers into one
import {AsyncStorage} from 'react-native';
import Console from '../Console';
// see here
// https://github.com/rt2zz/redux-persist/issues/58
// For why this is set up this way
const store = createStore(
rootReducer,
{},
compose(
autoRehydrate(),
applyMiddleware(
thunkMiddleware,
createLogger(),
))
);
persistStore(store, {storage: AsyncStorage}, () => {
Console.log('loaded store');
});
export default store;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment