我试图弄清楚如何为redux中的商店设置初始状态。我以https://github.com/reactjs/redux/blob/master/examples/todos- with- undo/reducers/index.js为例。我试图修改代码,以便待办事项已初始化一个值。
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 );