DEV Community

Discussion on: React cant reach current state

Collapse
justincy profile image
Justin • Edited on

Because of a stale closure, following the rules of Javascript closures and scope. dmitripavlutin.com/react-hooks-sta...

Here's what you want:

  const delet = (id) => {
    setUsers((currentUsers) => {
      return currentUsers.filter((i) => i.id !== id);
    });
  };
Enter fullscreen mode Exit fullscreen mode

codesandbox.io/s/the-appropriate-u...