加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 20:51:12 所属栏目:百科 来源:网络整理
导读:我正在试图弄清楚如何在redux中为商店设置初始状态.我以 https://github.com/reactjs/redux/blob/master/examples/todos-with-undo/reducers/index.js为例.我试图修改代码,以便todos初始化了一个值. const todoApp = combineReducers({ todos,visibilityFilt
我正在试图弄清楚如何在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
);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读