how to set initial state in redux

前端 未结 4 1049
梦如初夏
梦如初夏 2020-12-03 04:07

I\'m trying to figure out how to set an initial state for a store in redux. I\'m using https://github.com/reactjs/redux/blob/master/examples/todos-with-undo/reducers/index.j

4条回答
  •  伪装坚强ぢ
    2020-12-03 04:47

    It needs to be the second argument to createStore:

    const rootReducer = combineReducers({
      todos: todos,
      visibilityFilter: visibilityFilter
    });
    
    const initialState = { 
      todos: [{id:123, text:'hello', completed: false}] 
    };
    
    const store = createStore(
      rootReducer, 
      initialState
    );
    

提交回复
热议问题