我试图弄清楚如何在 redux 中设置商店的初始状态。我在用着https://github.com/reactjs/redux/blob/master/examples/todos-with-undo/reducers/index.js 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 http://redux.js.org/docs/api/createStore.html
但它不起作用,我不太清楚为什么。
它需要是第二个参数createStore
:
const rootReducer = combineReducers({
todos: todos,
visibilityFilter: visibilityFilter
});
const initialState = {
todos: [{id:123, text:'hello', completed: false}]
};
const store = createStore(
rootReducer,
initialState
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)