Clear an input field with Reactjs?

后端 未结 7 2054
囚心锁ツ
囚心锁ツ 2020-12-08 04:33

I am using a variable below.

var newInput = {
   title: this.inputTitle.value,
   entry: this.inputEntry.value    
};

This is used by my i

7条回答
  •  一向
    一向 (楼主)
    2020-12-08 04:57

    I have a similar solution to @Satheesh using React hooks:

    State initialization:

    const [enteredText, setEnteredText] = useState(''); 
    

    Input tag:

    
    

    Inside the event handler function, after updating the object with data from input form, call:

    setEnteredText('');
    

    Note: This is described as 'two-way binding'

提交回复
热议问题