Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如果签入,如何删除整行?_Reactjs_React Hooks - Fatal编程技术网

Reactjs 如果签入,如何删除整行?

Reactjs 如果签入,如何删除整行?,reactjs,react-hooks,Reactjs,React Hooks,我有一个5列的表。第一列有一个复选框,选中时,我可以编辑或删除整个选中行。我用反应钩子来做那件事。现在我可以编辑整行,但不能删除该行。这是我的密码 const handleCheckbox = id => { console.log("called"); const checkedRow = [...users]; checkedRow[id].select = !checkedRow[id].select; setUsers(checkedRow);

我有一个5列的表。第一列有一个复选框,选中时,我可以编辑或删除整个选中行。我用反应钩子来做那件事。现在我可以编辑整行,但不能删除该行。这是我的密码

  const handleCheckbox = id => {
    console.log("called");
    const checkedRow = [...users];
    checkedRow[id].select = !checkedRow[id].select;
    setUsers(checkedRow);
    setNewCheck([...checksArray, checkedRow]);

    // id = newCheck.length + 1;
    // setNewCheck([...newCheck, id]);
    console.log("checkArray", checksArray);
  };
在前面的代码中,我可以将行id传递给checkbox方法,然后我想将行id添加到数组中以删除它们

前面的代码属于数组和数组中的值


如何删除整行?我的方法是正确的还是有更好的方法?提前感谢。

请签出
useDispatch
@RamyM.Mousa谢谢,但我只想使用react hook构建它,而不重新使用任何想法?
checksArray
users
链接在
users
数组中向用户添加checked属性。这将比保持这两个阵列同步更容易。
const initialFormState = {
    id: null,
    code: "",
    englishName: "",
    arabicName: "",
    remarks: "",
    checkedGroup: []
  };

  // Setting state
  const [users, setUsers] = useState(usersData);
  const [checksArray, setNewCheck] = useState(initialFormState.checkedGroup);
  const [currentUser, setCurrentUser] = useState(initialFormState);
  const [editing, setEditing] = useState(false);