我试图弄清楚如何在 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
但它不起作用,我不太清楚为什么。
原文由 Saad 发布,翻译遵循 CC BY-SA 4.0 许可协议
它必须是
createStore
的第二个参数: