Created
April 18, 2019 20:03
-
-
Save maiquealmeida/4f7fcb63217512b60a9dc109b7c93081 to your computer and use it in GitHub Desktop.
Redux Store com Persist Gate (redux-persist), Reactotron Enhacer e Ducks Pattern.
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 '~/config/reactotron'; | |
import { Provider } from 'react-redux'; | |
import { PersistGate } from 'redux-persist/integration/react'; | |
import { store, persistor } from './store'; | |
import Routes from '~/config/routes'; | |
const App = () => ( | |
<Provider store={store}> | |
<PersistGate loading={null} persistor={persistor}> | |
<Routes /> | |
</PersistGate> | |
</Provider> | |
); | |
export default App; |
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, compose, applyMiddleware } from 'redux'; | |
import createSagaMiddleware from 'redux-saga'; | |
import { persistStore, persistReducer } from 'redux-persist'; | |
import storage from 'redux-persist/lib/storage'; | |
import reducers from './ducks'; | |
import sagas from './sagas'; | |
const persistConfig = { | |
key: 'root', | |
storage, | |
}; | |
const persistedReducer = persistReducer(persistConfig, reducers); | |
const middlewares = []; | |
const sagaMonitor = __DEV__ ? console.tron.createSagaMonitor() : null; | |
const sagaMiddleware = createSagaMiddleware({ sagaMonitor }); | |
middlewares.push(sagaMiddleware); | |
const composer = __DEV__ | |
? compose( | |
applyMiddleware(...middlewares), | |
console.tron.createEnhancer(), | |
) | |
: compose(applyMiddleware(...middlewares)); | |
const store = createStore(persistedReducer, composer); | |
const persistor = persistStore(store); | |
sagaMiddleware.run(sagas); | |
export { store, persistor }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment