0

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)?

zmii
  • 3,742
  • 2
  • 36
  • 59
  • No. if you change state of component **A** then **B** & **C** will be re-rendered because component **A** render function will be triggered. – Tareq Jan 18 '18 at 14:35

2 Answers2

0

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.

Dimitri Bosteels
  • 371
  • 4
  • 11
0

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.

Hemadri Dasari
  • 29,321
  • 31
  • 106
  • 146