V
V
vasIvas2016-01-06 16:41:38
JavaScript
vasIvas, 2016-01-06 16:41:38

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

2 answer(s)
R
Roman_Kh, 2016-01-06
@vasIvas

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)
      ....
  }
}

O
Oleg Krasnov, 2014-06-23
@NSidorov

www.paratype.ru/pstore/default.asp?fcode=TM_CRC&le...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question