Skip to content
Advertisement

Reseting react bootstrap’s form after the submit

I have a problem with reseting my Form after I submit it. I tried to do something like document.getElementById("formularz").reset(), but it doesn’t work, neither does doing in the end of handleOnSubmit things like: event.target.title="". It does reset the fields, but when I start writing new data, suddenly in each input there are shown data from previous submit.

My component:

JavaScript

Advertisement

Answer

JavaScript

Your form inputs are controlled by your state (as you put each input value to reflect the state property of the same name). In order for your form to reset, you need to set the state with a new object, structured as your current state – only with empty strings as values.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement