2

The normal way to set initial state (that overrides a reducer's own default initial state) while creating a store is to provide a second argument to createStore (how to set initial state in redux). But I've unfortunately cobbled together a tangle of stuff (pardon the mixed metaphor) that I don't really understand and I don't know where to put my desired initial state:

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(
  rootReducer,
  composeEnhancers(
    applyMiddleware(...middleware)
  )
);

I hope no one asks to see my combineReducers and middleware construction code 'cause that's even more embarrassing.

Community
  • 1
  • 1
Sigfried
  • 2,943
  • 3
  • 31
  • 43

1 Answers1

6

Still use second argument:

const store = createStore(
  rootReducer,
  { your: { initial: { state: {} } } },
  composeEnhancers(
    applyMiddleware(...middleware)
  )
);
fkulikov
  • 3,169
  • 13
  • 24