Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created January 27, 2020 21:46
Show Gist options
  • Save ozcanzaferayan/13bfd059d4ccd7b7657ea3831f47f992 to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/13bfd059d4ccd7b7657ea3831f47f992 to your computer and use it in GitHub Desktop.
redux-persist implementation
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);
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