Answer the question
In order to leave comments, you need to log in
How to subscribe a child to an event?
I have a parent component that creates several other child components that need to be very difficult to animate. That is, the parent component should track their position every tick and, based on the collected data, implement one or another scenario. And children must send events that the parent catches. explain in words how to do this?
Answer the question
In order to leave comments, you need to log in
For example, like this
class Parent {
....
handleChildTick(someData){
// обработать данные от потомка
// (указание на конкретного потомка можно вставить в структуру someData)
}
....
render(){
....
<Child ... onTick={this.handleChildTick} />
....
}
}
class Child {
....
someAction(){
....
if(this.props.onTick)
this.props.onTick(someData)
....
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question