I was creating a form using React, and displaying an array of users’ names and Ids. while adding a delete button to allow deleting a user from the list.
my question is when I added the handleDelete function
const handleDelete = (id) => { const newUsers = users.filter((person) => person.id !== id); setUsers(newUsers); };
when I add this function the the button as onClick={handleDelete(user.id)}
it doesn’t work but when I add it as onClick={() => handleDelete(user.id)}
it work, can anyone explain the difference between these two ways?