store.js 742 B

12345678910111213141516171819202122232425
  1. import { createStore, compose, applyMiddleware } from "redux";
  2. import thunk from "redux-thunk";
  3. import reducers from "./reducers/reducers";
  4. import { saveState } from "./persisted.store.cookies.js";
  5. export default function configureStore(initialState) {
  6. const enhancers = compose(typeof window !== "undefined" && window.devToolsExtension ? window.devToolsExtension() : (f) => f);
  7. // const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || enhancers;
  8. const store = createStore(
  9. reducers,
  10. enhancers(applyMiddleware(thunk))
  11. // {
  12. // ...initialState,
  13. // },
  14. // enhancers
  15. );
  16. // add a listener that will be invoked on any state change
  17. store.subscribe(() => {
  18. saveState(store.getState());
  19. });
  20. return store;
  21. }