如何在Redux中设置初始状态

我试图弄清楚如何为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

const rootReducer = combineReducers({

todos: todos,

visibilityFilter: visibilityFilter

});

const initialState = {

todos: [{id:123, text:'hello', completed: false}]

};

const store = createStore(

rootReducer,

initialState

);

以上是 如何在Redux中设置初始状态 的全部内容, 来源链接: utcz.com/qa/403273.html

回到顶部