Created
May 31, 2016 17:41
-
-
Save benvium/0967337fba314c3a8b058d45f0b0f08d to your computer and use it in GitHub Desktop.
React Native ConfigureStore including AutoRehydrate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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