首页 > 解决方案 > 从列表中删除待办事项后,我在显示待办事项内容时出错

问题描述

从列表中删除待办事项后,我在显示待办事项内容时出错。

https://codesandbox.io/embed/cool-resonance-bxuzk

标签: reactjsreact-hooks

解决方案


setTask里面的andfilter方法的问题handleDelete

const handleDelete = delt => {
  const newTask = task.filter((t, i) => {  // Make changes over here...
    return i !== delt;
  });
  setTask(newTask);  // Make changes over here...
};
const handleClone = index => {
  let clone = task;
  let Arr = clone[index];
  clone.push(Arr);
  setTask(clone);  // Make changes over here...
};

在这里,我为您创建了工作代码
https://codesandbox.io/s/thirsty-waterfall-v7px8

希望这对你有用。


推荐阅读