DEV Community

Discussion on: 20 Killer JavaScript One-Liners That’ll Save You Hours of Coding 🤯🔥

 
devdufutur profile image
Rudy Nappée

What do you mean by rerender ?

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

Like once in a project i mapped the Array item with HTML UI using method,
Then delete element with button click using filter method, What it was doing is refreshing the entire list of HTML element, like there is a update Dom method which sets the innerHTML of the list with the updated array
So it was doing a heavy operation with that filter array approach
Then i used the Event Propagation and find the element using closest() method of DOM, when we click on delete button of an element, it will find the closest parent element which holds that delete button and other Things, and then deleting that parent element using remove() method

Thread Thread
 
devdufutur profile image
Rudy Nappée

Actually with React you shouldn't mutate your state. If your keys are consistent it will not rerender your other elements. With filter, the objects identities doesn't change, only the array identity (it returns a new array containing the same objects).