generated from wednesday-solutions/react-native-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateStore.js
48 lines (40 loc) · 1.45 KB
/
createStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { applyMiddleware, compose, createStore } from 'redux';
import createSagaMiddleware from 'redux-saga';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { persistReducer, persistStore } from 'redux-persist';
import immutableTransform from 'redux-persist-transform-immutable';
/**
* This import defaults to localStorage for web and AsyncStorage for react-native.
*
* Keep in mind this storage *is not secure*. Do not use it to store sensitive information
* (like API tokens, private and sensitive data, etc.).
*
* If you need to store sensitive information, use redux-persist-sensitive-storage.
* @see https://github.com/CodingZeal/redux-persist-sensitive-storage
*/
const persistConfig = {
key: 'root',
transforms: [immutableTransform()],
storage: AsyncStorage,
/**
* Blacklist state that we do not need/want to persist
*/
blacklist: [
// 'auth',
]
};
export default (rootReducer, rootSaga) => {
const middleware = [];
const enhancers = [];
// Connect the sagas to the redux store
const sagaMiddleware = createSagaMiddleware();
middleware.push(sagaMiddleware);
enhancers.push(applyMiddleware(...middleware));
// Redux persist
const persistedReducer = persistReducer(persistConfig, rootReducer);
const store = createStore(persistedReducer, compose(...enhancers));
const persistor = persistStore(store);
// Kick off the root saga
sagaMiddleware.run(rootSaga);
return { store, persistor };
};