Answer the question
In order to leave comments, you need to log in
How to call a function on all react components by clicking on one button?
There is an application:
2 buttons - add a car, start the game
when you click on add a car, I add the Car component to the page, they have their own properties (id, color, move function)
how do I now, when I click on the Start game button, cause movement for all cars ?
Answer the question
In order to leave comments, you need to log in
You create a state in the main component using a hook (or using Redux), create a state update function in the same place. When the button is clicked, an event should be fired that will call the state update function. And forward the updated data using props
useState
props
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question