更新时间:2023-12-06 08:52:34
你不应该直接改变 state
.我没有试过你的整个代码
you should not directly mutate the state
. I have not tried your whole code
import {combineReducers} from 'redux';
const tasksReducer =(state=[] , action)=>{
switch(action.type){
case 'ADD_TASK':
let tempArr = [...state];
let arr = tempArr.concat(action.payload); //action.payload is an array
return [...arr];
break;
case 'DELETE_TASK':
let tempArr= [...state];
tempArr.splice(action.payload,1);//action.payload is index
return [...tempArr];
break;
default:
return state;
}
};
export default combineReducers({
tasks:tasksReducer
});
这是一个快速演示,演示了array concat 和 拼接
here is a quick demo demonstrating array concat and splice