React JS,Redux状态更新中出现逻辑错误



My Todo代码接受用户的新Todo并更新Redux存储。我的减速器功能似乎有问题


const initialState = {
tasks: ['notodo'],
completedTasks: ['nothing']
}
const todoState = (state = initialState, action) => {
switch(action.type) {
case 'ADDTODO':
return { 
...state,
tasks: [...tasks, action.payload]
};
default:
return state;
}
}
case 'ADDTODO':
return { 
...state,
tasks: [...tasks, action.payload] // Here ...tasks is undefined
};
It should be [...state.tasks, action.payload]

相关内容

  • 没有找到相关文章

最新更新