Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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