What is a combination of events in a reaction?

SyntheticEvent integrates. This means that the SyntheticEvent object will be reused and all properties will be invalidated after the callback is called. This is for performance reasons. Therefore, you cannot access the event asynchronously.

refer: Event system in action

+4
source share
1 answer

This means that event properties exist only with an active callback. Adding asynchronization to the mix or saving the event for future use will fail.

, console.log(event) . , null. script debugger; , .

class MyComponent extends React.Component {
    handleClick (e){
    console.log('The event currentTarget is', e.currentTarget); // DOM element
    setTimeout(() => {
    console.log('event.currentTarget was', e.currentTarget); // null
  }, 1000)
  }
  render () {
    return <button onClick={this.handleClick}>Fire event!</button>
  }
}

DOM null . , , event.target , .

+4

All Articles