Skip to content

Instantly share code, notes, and snippets.

@ger86
Created December 19, 2018 08:33
Show Gist options
  • Save ger86/36ec5c6dfeed4be0f71a17a7ea0b6d9a to your computer and use it in GitHub Desktop.
Save ger86/36ec5c6dfeed4be0f71a17a7ea0b6d9a to your computer and use it in GitHub Desktop.
configureStoreWithFSStorage.js
import { createStore, applyMiddleware } from 'redux';
import reduxThunk from 'redux-thunk';
import RNFS from 'react-native-fs';
import { Platform } from 'react-native';
import { persistStore, persistReducer } from 'redux-persist';
import FSStorage from 'redux-persist-fs-storage';
import rootReducer from 'WorthymApp/src/ducks';
const getFSStorage = () =>
Platform.OS === 'ios'
? RNFS.pathForGroup('group.app.appName').then(folder => FSStorage(folder))
: Promise.resolve(FSStorage());
const configureStore = callback =>
getFSStorage().then(fsStorage => {
const persistConfig = {
key: 'root',
storage: fsStorage,
blacklist: ['form']
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
const createStoreWithMiddleware = applyMiddleware(reduxThunk)(createStore);
const store = createStoreWithMiddleware(persistedReducer);
const persistor = persistStore(store, null, () => callback(store));
return { store, persistor };
});
export default configureStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment