码迷,mamicode.com
首页 > 其他好文 > 详细

Handling Event

时间:2017-03-22 10:35:26      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:logs   tar   ogg   function   git   code   undefined   problem   led   

Handling Event

1、React events are named using camelCase

  技术分享

2、You must call preventDefault explicitly to prevent default behaviour

  技术分享

3、define callback in class.

  技术分享\

   In JavaScript, class methods are not bound by default. If you forget to bind this.handleClick and pass it toonClickthis will be undefined when the function is actually called.

  Generally, if you refer to a method without () after it, such as onClick={this.handleClick}, you should bind that method.

 

4、you can use an arrow function in the callback to ensure this pointer

  技术分享

  This has performance problem. Do not use arrow function to solve the problem.  

  The problem with this syntax is that a different callback is created each time theLoggingButton renders. In most cases, this is fine. However, if this callback is passed as a prop to lower components, those components might do an extra re-rendering. We generally recommend binding in the constructor or using the property initializer syntax, to avoid this sort of performance problem.

参考:https://facebook.github.io/react/docs/handling-events.html

 

Handling Event

标签:logs   tar   ogg   function   git   code   undefined   problem   led   

原文地址:http://www.cnblogs.com/tekkaman/p/6598527.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!