store.js 644 B

123456789101112131415161718192021222324
  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 store = createStore(
  8. reducers,
  9. applyMiddleware(thunk)
  10. // {
  11. // ...initialState,
  12. // },
  13. // enhancers
  14. );
  15. // add a listener that will be invoked on any state change
  16. store.subscribe(() => {
  17. saveState(store.getState());
  18. });
  19. return store;
  20. }