redux的action怎么调用其他的reducer 的返回值

redux的action怎么调用其他的reducer 的返回值


繁星点点滴滴
浏览 1458回答 1
1回答

RISEBY

在todo例子中,按照官方文档把state拆分成todos和visibility,现在我在另一个reducer中需要用到todos,比如设置所有的todos的completed为true(false),这个具体要怎么做?以下是代码function todos(state = initialState, action) {switch (action.type) {case ADD_TODO:return [...state,{text: action.text,competed: false}];default:return state;}}function allCompleted(state, action) {switch (action.type) {case YES:return xxxx;//这里要怎么实现,才能引用到或者共享上面的todos,因为要遍历所有todo的completed属性,default:return state;}}解决方案1:新加两个action,然后把allComleted函数放在todos函数里面,操作同一个state下的todos树
打开App,查看更多内容
随时随地看视频慕课网APP