Answer the question
In order to leave comments, you need to log in
Which of the implementations of the method is more efficient, which one is better to use and why?
Actually, here are the methods:
The first option:
deleteItem = (id) =>
{
this.setState(
({ toDoData })=>
{
const dummyState = JSON.parse( JSON.stringify( toDoData ));
dummyState.splice(toDoData.findIndex(( item ) => item.id === id), 1);
return{
toDoData: dummyState
}
}
)
}
deleteItem = (id) =>
{
this.setState
(
({ toDoData })=>
{
let indexItem = toDoData.findIndex(( item ) => item.id === id);
const dummyState = [...toDoData.slice(0, indexItem), ...toDoData.slice(indexItem + 1)]
return{
toDoData: dummyState
}
}
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question