React’s diffing algorithm allows developers to author user interfaces in a declarative way, without worrying about how to handle updates when the backing data changes. When a component is updated, React only applies the parts that changed to the DOM. This results in fluid interface transitions, devoid of flickering.
When I was learning React, an assumption I made was that a component will only be re-rendered if something it depends on changes, e.g. a passed in property or the component’s own state is updated. I was surprised to learn this is not true.
Part of the misconception was that I didn’t understand that rendering a component and updating the DOM for that component are two separate steps in the lifecycle. The component has to be re-rendered in order for the diffing algorithm to compare it to the previous output. If the output is different, it will update the DOM accordingly. Re-rendering often isn’t necessarily a bad thing; components are typically small, focused, and cheap. In my case the component was not cheap, and it was being re-rendered
... read the whole story at robots.thoughtbot.com.