Reputation: 471
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
Reputation: 1028
Set value={textField}
on the Form.Control
, that should fix it :)
Upvotes: 1