React and text inputs - use onBlur or onChange?

后端 未结 3 1393
渐次进展
渐次进展 2021-01-14 03:59

I am working on a form with about 6 text input fields.

To save the values to my state, is it better to do so onBlur or onChange?

F

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 04:12

    For many input fields it is difficult to handle the form state on your own so you may use Redux Form it handles the state on it own.

    See this link https://redux-form.com/7.4.2/examples/simple/

    anyway onBlur would be a best practice in handling form input state because onChange may set the state whenever the a change is made in input field for example if you type "name" in input field it sets state for 4 times so the page may re render 4 times,But on onBlur after the focus is out of input field the state is set.

提交回复
热议问题