Reputation: 6675
In React, if a child component renders, does the parent component render too? Or only the child component itself get rendered?
Upvotes: 0
Views: 500
Reputation: 281656
Short Answer: React doesn't re-render parent if the child component re-renders
Long Answer The way re-renders and diffing works with react is through a virtual dom and a reconcilation process.
React creates a tree like structure of your app hierarchy and compares code levelwise
So at any level if there is a change, react triggers render function of all children below it in the hierarchy. Obviously triggering render function doesn't mean things change in the dom only changes relevant to elements are being updated in the dom.
Upvotes: 3