baumli
baumli

Reputation: 471

Reset form field to Initial State on submit with React Hooks

I'm trying to reset my form fields to blank when a button is pressed. For some reason its not working. Here is my sample code:

initialize:

function App() {
  const [textField, setTextField] = useState(""); 

Clear the state:

  const clearState = () => {
    setTextField('');
  }

On submit:

  const submitForm = () => {
    clearState();
  };

Form field:

        <Form.Group controlId="textField">
          <Form.Control placeholder="Description" onChange={handleTextFieldInput} />
        </Form.Group>

But when I submit, the value is still the same as was input.

Upvotes: 1

Views: 2349

Answers (1)

Albert Alises
Albert Alises

Reputation: 1028

Set value={textField} on the Form.Control, that should fix it :)

Upvotes: 1

Related Questions