React - State 和生命周期
React - 条件渲染

React - 事件处理

violet posted @ Jul 17, 2020 06:19:23 AM in 读书笔记 with tags React , 490 阅读

React 元素的事件处理和 DOM 元素的很相似,但是有一点语法上的不同:
1. React事件的命名采用驼峰,而不是纯小写
2. 使用 jsx 语法时需要传入一个函数作为事件处理函数,而不是一个字符串
3. 不能通过返回 false 的方式阻止没人行为。必须显式地使用 preventDefault。
4. 在使用 React 时,一般不需要使用 addEventListener 为已经创建的 DOM 元素添加监听器。只需要在该元素初始渲染的时候添加监听器即可。

事件处理程序传递参数

<button onClick={(e) => this.deleteRow(id, e)}>Delete Row</button>
<button onClick={this.deleteRow.bind(this, id)}>Delete Row</button>

上述两种方法是等价的,分别通过箭头函数和 Function.prototype.bind 来实现。
在这两种情况下,React 的事件对象 e 会被当作第二个参数传递。如果通过箭头函数的方式,事件对象必须显式的进行传递,而通过 bind 的方式,事件对象以及更多的参数将会被隐式的方式进行传递。

  • 无匹配
charlly 说:
Dec 20, 2022 10:45:59 AM

Monte Carlo integration is a method of numerical integration that uses random numbers to approximate the value of a function. It is often used when the function is difficult to integrate, or when the number of dimensions is too large for traditional methods to be effective. Monte Carlo integration can be used to estimate a wide variety of quantities, including the area of a region, the Brand Building Story Of Aisha Nikole volume of a solid, and the expectation of a random variable.

pavzi.com 说:
Jan 09, 2024 02:28:03 PM

Pavzi.com provides all the news about Gadgets, the Economy, Technology, Business, Finance and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us. pavzi.com Our site is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter