简体   繁体   English

用于捕获和存储在 React Js 应用程序中输入的数据的最佳事件处理程序

[英]Best Event Handler for capturing and storing the data entered in React Js Application

I have created an input textbox for entering items details.我创建了一个用于输入项目详细信息的输入文本框。 To capture and store the data entered, which among below mentioned event handler is the best?要捕获和存储输入的数据,下面提到的事件处理程序中哪个是最好的?

  • onClick onClick
  • onChange改变
  • onLoad负载
  • onKeyPress onKeyPress

You need the onChange event handler to get the value of the input.您需要 onChange 事件处理程序来获取输入的值。 It would look like this:它看起来像这样:

onChange={e => setText(e.target.value)}

Using useState hook:使用useState钩子:

const [text, setText] = useState('')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM