//下面是一个reducer
import { USER_EDIT } from '../actions/actions'
const editUsers = (state = USER_EDIT , action)=>{
switch(action.type){
case USER_EDIT:
return Object.assign({},action.obj)
default:
return state
}
}
export default editUsers
//下面也是一个reducer
const todos = (state = [] ,action)=>{
switch(action.type){
case USER_ADD :
...
}
}
export default todos
//下面是combineReducers
import React , {combineReducers} from 'redux'
import todos from './todos'
import editUsers from './edit'
const lists = combineReducers({
todos,
editUsers
})
问题来了,调试时发现只有todos这个reducer生效,editUsers这个ruducer不起作用,这是为什么?
补充 actions export const USER_ADD = 'USER_ADD';
export const USER_EDIT = 'USER_EDIT'
export const USER_DEL = 'USER_DEL'
export const USER_LIST = 'USER_LIST'
export const USER_INFO = 'USER_INFO'
export const USER_EDIT_SUB = 'USER_EDIT_SUB'
let count = 0;
export function addUser(obj){
obj.key = count++;
return {
type: USER_ADD,
obj
}
}
export function delUser(id){
return {
type: USER_DEL,
id
}
}
export function editUser(obj){
return {
type: USER_EDIT,
obj
}
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
看着没问题啊,具体错误贴一下吧。。
目测有两个错误
1.import改为这样
2.editUsers这个reducer的第一个参数,state = USER_EDIT 等于一个字符串,明显错误,默认state为{}或某个对象。还有Object.assign({}, state, action.obj)