title: Why do I get “Reducer [...] returned undefined during initialization” despite providing initialState to createStore()?
body: <p>I had set InitialState in my redux createStore method ,and I corresponding InitialState as second arguments </p>
  
  <p>I got a error in browser:</p>
  
  <pre><code>&lt;code&gt;Uncaught Error: Reducer "postsBySubreddit" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined.&lt;/code&gt;
  </code></pre>
  
  <p>code is here:</p>
  
  <pre><code>import { createStore, applyMiddleware } from 'redux'
  import thunkMiddleware from 'redux-thunk'
  import createLogger from 'redux-logger'
  import rootReducer from '../reducers/reducers'
  import Immutable from 'immutable'
  const loggerMiddleware = createLogger()
  //const initialState=0
  function configureStore() {
      return createStore(
      rootReducer,
       {postsBySubreddit:{},selectedSubreddit:'reactjs'},
       applyMiddleware(
       thunkMiddleware,
      loggerMiddleware
    )
   )
  }
    export default configureStore
  </code></pre>
  
  <p>and I invoked <code>configeStore</code>method in <code>Root.js</code>:</p>
  
  <pre><code> import React, { Component } from 'react'
   import { Provider } from 'react-redux'
   import configureStore from '../store/configureStore'
   import AsyncApp from './AsyncApp'
   import Immutable from 'immutable'
   const store = configureStore()
   console.log(store.getState())
   export default class Root extends Component {
   render() {
     return (
       &lt;Provider store={store}&gt;
         &lt;AsyncApp /&gt;
       &lt;/Provider&gt;
    )
   }
  }
  </code></pre>
  
  <p>but I guess this <code>initateState</code> has something wrong:</p>
  
  <pre><code>import { combineReducers } from 'redux'
  import {reducerCreator} from '../utils/creator'
  import Immutable from'immutable'
  import {SELECT_SUBREDDIT, INVALIDATE_SUBREDDIT ,REQUEST_POSTS, RECEIVE_POSTS} from '../actions/action'
  let initialState=Immutable.fromJS({isFetching: false, didInvalidate: false,items:[]})
  
  function selectedSubreddit(state, action) {
    switch (action.type) {
    case SELECT_SUBREDDIT:
      return action.subreddit
    default:
      return state
    }
  }
  function postsBySubreddit(state, action) {
    switch (action.type) {
      case INVALIDATE_SUBREDDIT:
      case RECEIVE_POSTS:
      case REQUEST_POSTS:
        return Object.assign({}, state, {
          [action.subreddit]: posts(state[action.subreddit], action)
        })
      default:
        return state
    }
  }
  function posts(state=initialState,action) {
    switch (action.type) {
      case INVALIDATE_SUBREDDIT:
        return state.merge({
          didInvalidate: true
        })
      case REQUEST_POSTS:
        return state.merge({
          isFetching: true,
          didInvalidate: false
        })
      case RECEIVE_POSTS:
        return state.merge({
          isFetching: false,
          didInvalidate: false,
          items: action.posts,
          lastUpdated: action.receivedAt
        })
      default:
        return state 
      }
  }
  
  const rootReducer = combineReducers({
    postsBySubreddit,
   selectedSubreddit
  })
  export default rootReducer
  </code></pre>
  
  <p>but if I set <code>initialState</code> in my every sub reducer it can did word normally. Something wrong? </p>