首页 > 其他 > 详细

[React] Normalize Events with Reacts Synthetic Event System

时间:2017-02-06 20:51:45      阅读:206      评论:0      收藏:0      [点我收藏+]

Event handlers are passed an instance of SyntheticEvent in React. In this video we‘ll take a look at the wide range of events available to us, including Touch events.

 

class App extends React.Component {
  constructor(){
    super();
    this.state = {currentEvent: ‘---‘}
    this.update = this.update.bind(this)
  }
  update(e){
    this.setState({currentEvent: e.type})
  }
  render(){
    return (
      <div>
        <textarea
          onKeyPress={this.update}
          onCopy={this.update}
          onCut={this.update}
          onPaste={this.update}
          onFocus={this.update}
          onBlur={this.update}
          onDoubleClick={this.update}
          onTouchStart={this.update}
          onTouchMove={this.update}
          onTouchEnd={this.update}
          cols="30"
          rows="10" />
        <h1>{this.state.currentEvent}</h1>
      </div>
    )
  }
}

ReactDOM.render(
  <App />,
  document.getElementById(‘root‘)
);

 

[React] Normalize Events with Reacts Synthetic Event System

原文:http://www.cnblogs.com/Answer1215/p/6371601.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!