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

Viewed 21

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
  • onChange
  • onLoad
  • onKeyPress
1 Answers

You need the onChange event handler to get the value of the input. It would look like this:

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

Using useState hook:

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

Related