How do I programatically fill input field value with React?

前端 未结 4 785
情歌与酒
情歌与酒 2021-01-05 14:28

I have a modal with some input fields. I can easily pass the data automatically with the user typing an input, using onChange function in the input field, as

4条回答
  •  [愿得一人]
    2021-01-05 14:43

    Use controlled component for this situation, define a value property of input element like this:

    Whenever you will update that variable, automatically that value will get populated in input element.

    Now you can populate some default value by assigning a value to variable_name and user can update that value by onChange function.

    As per DOC:

    An input form element whose value is controlled by React in this way is called a "controlled component".

提交回复
热议问题