我正在尝试弄清楚如何在 redux 中为商店设置初始状态。我使用https://github.com/reactjs/redux/blob/master/examples/todos-with-undo/reducers/index.js作为示例。我尝试修改代码,使 todos 具有初始化值。
const todoApp = combineReducers({ todos, visibilityFilter }, { todos: [{id:123, text:'hello', completed: false}] })
遵循文档:http://redux.js.org/docs/api/createStore.html
但它不起作用,我也不太清楚为什么。
它需要是第二个参数createStore:
createStore
const rootReducer = combineReducers({ todos: todos, visibilityFilter: visibilityFilter }); const initialState = { todos: [{id:123, text:'hello', completed: false}] }; const store = createStore( rootReducer, initialState );