yarn add -D redux@4.0.0 react-redux@5.0.7 redux-saga@0.16.0;
yarn add -D react-router-redux@5.0.0-alpha.9 react-router-dom@4.2.2 history@4.7.2;
yarn add -D react-hot-loader@4.1.1;
yarn upgrade-interactive;
mkdir -p src/redux src/ducks
yarn add -D redux@4.0.0 react-redux@5.0.7 redux-saga@0.16.0;
yarn add -D react-router-redux@5.0.0-alpha.9 react-router-dom@4.2.2 history@4.7.2;
yarn add -D react-hot-loader@4.1.1;
yarn upgrade-interactive;
mkdir -p src/redux src/ducks
// src/App.js | |
import React from 'react'; | |
import {Provider} from 'react-redux'; | |
import {ConnectedRouter} from 'react-router-redux'; | |
import {history} from './history'; | |
import {store} from './redux/store'; | |
import {Root} from './components/Root'; | |
export const App = () => <Provider store={store}> | |
<ConnectedRouter history={history}> | |
<Root/> | |
</ConnectedRouter> | |
</Provider>; |
// src/history.js | |
import createHistory from 'history/createBrowserHistory' | |
export const history = createHistory(); |
// src/index.js | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import {App} from './App.js'; // check import path | |
const mountRoot = document.querySelector('#root'); // change this | |
if (process.env.NODE_ENV !== 'production') { | |
const AppContainer = require('react-hot-loader').AppContainer; | |
const render = Component => { | |
ReactDOM.render( | |
<AppContainer> | |
<Component/> | |
</AppContainer>, | |
mountRoot | |
); | |
}; | |
render(App); | |
if (module.hot) { | |
module.hot.accept('./App.js', () => {// check import path | |
render(App); | |
}); | |
} | |
} else { | |
ReactDOM.render(<App/>, mountRoot); | |
} |
// src/redux/reducer.js | |
import {combineReducers} from 'redux'; | |
import {routerReducer as router} from 'react-router-redux'; | |
export const reducer = combineReducers({ | |
router | |
}); |
// src/redux/saga.js | |
const sagas = []; | |
export const runAllSagas = middleware => sagas.forEach(saga => middleware.run(saga)); |
// src/redux/store.js | |
import {applyMiddleware, createStore} from 'redux'; | |
import {routerMiddleware} from 'react-router-redux'; | |
import createSagaMiddleware from 'redux-saga'; | |
import {history} from '../history'; | |
import {reducer} from './reducer'; | |
import {runAllSagas} from './saga'; | |
const sagaMiddleware = createSagaMiddleware(); | |
const enhancer = process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ | |
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__( | |
applyMiddleware(sagaMiddleware, routerMiddleware(history)) | |
) | |
: applyMiddleware(sagaMiddleware, routerMiddleware(history)); | |
export const store = createStore(reducer, enhancer); | |
runAllSagas(sagaMiddleware); | |