• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: React: Passed states to child components don’t get updated when they change within the parent

Resolved: React: Passed states to child components don’t get updated when they change within the parent

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have read similar questions, but still can’t explain why the passed state to child components, which is defined as a separate state in there (for event controlling reasons), doesn’t get updated and therefore renders the children, while it got updated in the parent.
Please check this CodeSandbox or the below snippet to see the problem. (The parent state changes on inputs’ onChange event in child components, but it doesn’t re-render the children with the updated value).


Thanks.

Answer:

In your InputComponent you set the value using internal state. You assign it once and that’s it. Once it’s assigned it’s original value it doesn’t keep listening to changes in the passed down state.
Or you can useEffect to listen to changes

If you have better answer, please add a comment about this, thank you!

reactjs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Resolved: Passing 2 functions in onChange in react

24/03/2023

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.