I have a list of components and want to set each component as selected when the user clicks on it.
The flow looks like
Dashboard
⎿ MyList
⎿ MyItem -
Dan Abramov mentions another clever way to access a state change from outside a component class. Technically the setState
function still has to be called from within the component class anyway, so it's not REALLY outside the component, but this allows you to set the state of different components in the same fashion if you want, from the returned value of a function.
Basically, you can pass in a function into the setState()
function, and the state will be set to the returned value of that function.
you can see his post here: https://twitter.com/dan_abramov/status/824308413559668744?lang=en