Last active
April 25, 2020 20:29
-
-
Save kalysr/0db71aa0953869a0c2381a2a645d65a3 to your computer and use it in GitHub Desktop.
This file contains 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 { applyMiddleware, createStore } from "redux"; | |
import { createLogger } from "redux-logger"; | |
import thunk from "redux-thunk"; | |
import { composeWithDevTools } from "redux-devtools-extension/developmentOnly"; | |
import { routerMiddleware } from "connected-react-router"; | |
import { createBrowserHistory } from "history"; | |
import { createRootReducer } from "./reducers"; | |
export const history = createBrowserHistory(); | |
// Build the middleware for intercepting and dispatching navigation actions | |
const myRouterMiddleware = routerMiddleware(history); | |
const getMiddleware = () => { | |
if (process.env.NODE_ENV === "production") { | |
return applyMiddleware(thunk, myRouterMiddleware); | |
} else { | |
// Enable additional logging in non-production environments. | |
return applyMiddleware(thunk, myRouterMiddleware, createLogger()); | |
} | |
}; | |
export const store = createStore( | |
createRootReducer(history), | |
composeWithDevTools(getMiddleware()) | |
); |
Author
kalysr
commented
Apr 24, 2020
//reducers/index.js
import { combineReducers } from "redux";
import { connectRouter } from "connected-react-router";
export const createRootReducer = (history) => {
return combineReducers({
router: connectRouter(history),
});
};
``
`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment