I have an React application that has the following structure:
component A is composed of B and C
If I call setState
in component B, will component A and C be also notified (meaning they will also re-render at least enter reconciliation phase)?
I have an React application that has the following structure:
component A is composed of B and C
If I call setState
in component B, will component A and C be also notified (meaning they will also re-render at least enter reconciliation phase)?
the setState only update the state of the component, causing a re-rendering of this component (and so all of its child components). If B has no child, it will only re-render B. You can learn more about the lifecycle of component here. There is a way though to trigger something in the parent component but is this what you want? If yes, I can tell you more.
One more thing doing setState in componentWillMount won't trigger re-rendering because componentWillMount is invoked before your component renders. This principle applies to all parent and child components.