79356359

Date: 2025-01-14 21:03:40
Score: 0.5
Natty:
Report link

There seems to be nothing wrong here. Let's follow step by step:

  1. The initial state is "hello". Then you click and set it to "hi". (this was the first click.) Parent re-renders as the setState is called, and updates the state. Child also re-renders because the state is changed and i has a different value than before.
  2. You click the button a second time. This time the state is already "hi", and you are setting it to "hi" again. Therefore setState is called, parent re-renders because of the setState, but the state is not changed. So the Child Component doesn't re-render.

React listens to state changes, if the prop value didnot change, re-render is not triggered.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Berkay G.