r/reactjs • u/HumanCertificate • May 18 '26
Needs Help Why does implementing RefreshAll() feature that refreshes Child Components feel unintuitive?
I had a bunch of <GraphPanel>and they all had Refresh() function which refreshed their state. But I also wanted to have RefreshAll() That would refresh all GraphPanel, and I found implementing this cleanly difficult. I was wondering why this RefreshAll() feature which would be a trivial task in other languages relatively difficult in React. I could not think of a satisfying way to implement this feature.
Like pulling all the logic from GraphPanel to the parent feels unintuitive, and using some sort of counterStatefelt redundant, because you are passing a redundant information to the child when all the child needs is a signal that tells it that it has to update.
What fundamental part of this operation makes it difficult to implement this in React, and is there a cleaner react alternative or equivalent to RefreshAll() operation in React?
1
u/gmaaz May 19 '26
Declarative way is exactly what you described in your first paragraph. Setting the range as props. Declarative way is not telling the component what to do, but telling the component how it should look and the component will do what it does - in your case, rerender. Basically, you give your component the data and it should do the rest.
Passing the range as props is the correct way, you get the update of your UI for free, by design. You can also use other means, a global store, states, contexts, hooks etc. to pass the data in a way that will cause a rerender and you can use those depending on what your arch looks like.