Hmm ... Not sure if this will respond as an answer, but it has become too long for comment.
Imagine that you have a dashboard containing widgets showing the various states of the system. Each widget has its own data source and its own controls. Perhaps they are updated from time to time. However, when the user wants to see the updated view of the system, at the toolbar level there is a button "Update". The implementation of such a button is not trivial.
If you are in the Redux application, you will have a choice - "faking" dispatch('refresh') for all children. To separate it, each widget after loading registers an action, so the parent simply goes through all the actions and launches them when a mandatory update is required.
On a system without Redux / Flux or in more complex / dynamic scenarios, this may not be possible or may not be so simple. Then it might be better, more difficult, to expose the refresh method for all widgets, and then get access to it from the parent (or, rather, the owner):
class WidgetA extends React.Component { refresh() { console.log('WidgetA refreshed'); } render() { return ( <h3>WidgetA</h3> ); } } class WidgetB extends React.Component { refresh() { console.log('WidgetB refreshed'); } render() { return ( <h3>WidgetB</h3> ); } } class Dashboard extends React.Component { constructor() { super(); this.onRefresh = this.handleRefresh.bind(this); this.onRegister = this.handleRegister.bind(this); this.widgets = []; } handleRegister(widget) { this.widgets.push(widget); } handleRefresh() { this.widgets.forEach((widget) => { widget.refresh(); }); } render() { return ( <div> <button onClick={this.onRefresh}>Refresh</button> <hr /> <WidgetA ref={this.onRegister} /> <WidgetB ref={this.onRegister} /> </div> ); } }
Something like this, with less detail, of course.
As a side note, I confirmed @skav's answer and I think these scenarios should be avoided. This is an exception.
CodePen Example
source share