reactjs – 如何在redux中设置初始状态

前端之家收集整理的这篇文章主要介绍了reactjs – 如何在redux中设置初始状态前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在试图弄清楚如何在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的第二个参数:
const rootReducer = combineReducers({
  todos: todos,visibilityFilter: visibilityFilter
});

const initialState = { 
  todos: [{id:123,completed: false}] 
};

const store = createStore(
  rootReducer,initialState
);
原文链接:https://www.f2er.com/react/301139.html

猜你在找的React相关文章