score:3

Accepted answer

the return value of the splice method are the elements removed from the original array, not the array without the removed elements. i think the splice method is working just fine, you are using it wrong.

you shouldn't use splice in a variable handled by usestate cause splice changes the original array. you should copy it and then set it:

const deletetodo = (todo) => {
  const aux = [...todos];
  aux.splice(todo, 1);
  settodos(aux);
};

Related Query

More Query from same tag