Loading...
function remove(index) {
setTodos(todos.splice(index, 1));
}function remove(index) {
setTodos(todos.toSpliced(index, 1));
}splice() mutates state and returns the removed item; toSpliced() returns a new array without it.
toSpliced() to return the removed items, as splice() does.toSpliced(), not the removed items as with splice().-1 before calling toSpliced(i, 1).Use a delete count of 0: arr.toSpliced(index, 0, item) returns a copy with item inserted.
toSpliced() or filter() to remove items?Use toSpliced() to remove by position and filter() to remove by condition.