-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigureStore.js
36 lines (28 loc) · 1.16 KB
/
configureStore.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
import { createStore, applyMiddleware } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import ExpoFileSystemStorage from 'redux-persist-expo-filesystem';
import { createNetworkMiddleware, offlineActionTypes, checkInternetConnection } from 'react-native-offline';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
import { middleware } from './navigation/AppNavigator';
const networkMiddleware = createNetworkMiddleware();
const config = {
key: 'alpha-1',
storage: ExpoFileSystemStorage,
};
const pReducer = persistReducer(config, rootReducer);
// // const persistor = persistStore(store);
export default function configureStore(callback) {
const store = createStore(pReducer, applyMiddleware(networkMiddleware, thunk, middleware));
persistStore(store, null, () => {
// After rehydration completes, we detect initial connection
checkInternetConnection().then(isConnected => {
store.dispatch({
type: offlineActionTypes.CONNECTION_CHANGE,
payload: isConnected,
});
callback(); // Notify our root component we are good to go, so that we can render our app
});
});
return store;
}