初始化之前无法访问“ variableName”

当我单击删除按钮时,我想过滤出该ID并重新呈现该列表,但是标题中提到了一个令人讨厌的错误。

It will eventually send a request to the server to delete from the database but for now all I want is the item to be removed from the list and the list to show up again without that particular record. It is basically a table with a bunch of records. Each one has a delete button next to it. When you click delete it should remove that item which is what I am trying to do with .filter and then set the state to the new loadedFaq minus the record that was filtered out.

按钮:

<Button
  color="purple"
  label="Delete"
  onClick={() => deleteHandler(faq)}
/>

删除处理程序:

  const deleteHandler = async (faq) => {
    const originalFaq = loadedFaq; // loadedFaq is the original state
    const loadedFaq = originalFaq.filter((f) => f._id !== faq._id);
    setLoadedFaq(loadedFaq); // set the state to the original state minus the filtered out record
  };