Read Store's Initial State in Redux Reducer

前端 未结 4 1958
慢半拍i
慢半拍i 2020-11-29 15:30

Initial state in a Redux app can be set in two ways:

  • pass it as the second argument to createStore (docs link)
  • pass it as the first argum
4条回答
  •  爱一瞬间的悲伤
    2020-11-29 16:00

    how do you read that state from the store and make it the first argument in your reducers?

    combineReducers() do the job for you. The first way to write it is not really helpfull :

    const rootReducer = combineReducers({ todos, users })
    

    But the other one, that is equivalent is more clear :

    function rootReducer(state, action) {
       todos: todos(state.todos, action),
       users: users(state.users, action)
    }
    

提交回复
热议问题