Created
January 27, 2020 21:46
-
-
Save ozcanzaferayan/13bfd059d4ccd7b7657ea3831f47f992 to your computer and use it in GitHub Desktop.
redux-persist implementation
This file contains hidden or 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
import React from 'react'; | |
import { AppRegistry } from 'react-native'; | |
import { StatusBar } from 'react-native'; | |
import { name as appName } from './app.json'; | |
import AppNavigator from 'containers/AppNavigator'; | |
import { createAppContainer } from 'react-navigation'; | |
import { store } from 'store'; | |
import { Provider } from 'react-redux'; | |
import { PersistGate } from 'redux-persist/integration/react' | |
import { persistor } from 'store'; | |
StatusBar.setBarStyle('light-content', true); | |
StatusBar.backgroundColor = '#000'; | |
const Navigation = createAppContainer(AppNavigator); | |
const Root = () => ( | |
<Provider store={store}> | |
<PersistGate loading={null} persistor={persistor}> | |
<Navigation/> | |
</PersistGate> | |
</Provider> | |
); | |
AppRegistry.registerComponent(appName, () => Root); |
This file contains hidden or 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
import { createStore, applyMiddleware } from 'redux'; | |
import { persistStore, persistReducer } from 'redux-persist'; | |
import rootReducer from 'reducers'; | |
import logger from 'redux-logger'; | |
import createSagaMiddleware from 'redux-saga'; | |
import rootSaga from 'sagas'; | |
import { AsyncStorage } from 'react-native'; | |
const persistConfig = { | |
key: 'root', | |
storage: AsyncStorage, | |
}; | |
const sagaMiddleware = createSagaMiddleware(); | |
const persistedReducer = persistReducer(persistConfig, rootReducer); | |
export const store = createStore(persistedReducer, applyMiddleware(sagaMiddleware, logger)); | |
export const persistor = persistStore(store); | |
sagaMiddleware.run(rootSaga); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment