Handling Event

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

时间: 2024-08-09 14:46:51

Handling Event的相关文章

c# 关键字delegate、event(委托与事件)[MSDN原文摘录][1]

A delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++. Unlike C function pointers, delegates are object-oriented, type safe, and secure. The type of a delegate is defined by the name of the delegate. The f

C#学习日记24----事件(event)

事件为类和类的实例提供了向外界发送通知的能力,实现了对象与对象之间的通信,如果定义了一个事件成员,表示该类型具有 1.能够在事件中注册方法 (+=操作符实现). 2.能够在事件中注销方法(-=操作符实现). 3.当事件被触发时注册的方法会被通知(事件内部维护了一个注册方法列表).委托(Delegate)是事件(event)的载体,要定义事件就的要有委托.  有关委托的内容请点击 委托(De... www.mafengwo.cn/event/event.php?iid=4971258www.maf

c#+jquery.autocomplete.js

html代码: $(document).ready(function () { $.ajax({ type: "POST", contentType: "json", url: "a.ashx?action=findlist", data: "{}", dataType: "html", success: function (data) { var dataset = eval('(' + data + '

resource manager因为CapacityScheduler的NPE异常退出,引起failover切换

一.问题描述 yarn2.0发生resource manager down(master2)掉,并引起resource manager的failover切换 二.问题分析 1)看master2上resource manager的日志 2016-06-26 12:35:41,504 INFO org.apache.hadoop.yarn.server.resourcemanager.RMAuditLogger: USER=warehouse        OPERATION=AM Released

yarn RM crash问题一例

今天收到线上的resource manager报警: 报错信息如下: 2014-07-08 13:22:54,118 INFO org.apache.hadoop.yarn.util.AbstractLivelinessMonitor: Expired:xxxx:53356 Timed out after 600 secs 2014-07-08 13:22:54,118 INFO org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNod

Android Ethernet从上至下解析一

最近遇到不少框架问题,比如关于网口的,开机后拔掉有线网,状态栏和设置项中有线网显示图标不会更新,还有双网口的需求,下面就带着这个问题,以跟踪网络状态问题为引线,本篇将贯穿分析Ethernet从上至下的框架结构.因能力和时间有限,文中有分析不到位的地方,十分欢迎大侠们拍砖. 首先看下应用层网络监听相关的app 网络监听一:设置 packages/apps/Settings/src/com/android/settings/ethernet/EthernetEnabler.java 设置项网络按钮类

yarn空队列crash bug

最近线上的rm crash了一次,查看日志,发现有如下报错: 2015-01-05 18:00:11,523 ERROR org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler: Request for appInfo of unknown attemptappattempt_1418702129929_2281200_000001 2015-01-05 18:00:11,524 ERROR org.a

jquery autocomplete ajax获取动态数据,兼容各浏览器,支持中文

jquery.autocomplete.js经过改动,支持各种浏览器.支持中文输入! 1.效果图例如以下 2.HTML和ajax代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html

Android—— 4.2 Vold挂载管理_MountService (六)

整个Vold机制应该算system层,与framwork层的交互在Android-- 4.2 Vold挂载管理_CommandListener (二)中有提到过,是通过一个"vold"的socket进行通信的,这里分析一下framework中负责与Vold通信的:MountService 撰写不易,转载请注明出处:http://blog.csdn.net/jscese/article/details/38978387 一.MountService启动: 在/frameworks/bas