3
votes

Is there a way to reset the form and set the state at the same go? I tried the below code and it does not seem to work. Any inputs are appreciated.

<Form
    onSubmit={this.onSubmit}
    render={({handleSubmit, form, submitting, pristine, values}) => (
        <form onSubmit={handleSubmit}>
.
.
.
.

<button
    type="button"
    onClick={() => {
        form.reset;
        this.setState({"reset": true});
    }}
    disabled={submitting || pristine}
>
    Reset
</button>
</form>
2
There's no reason why that should not be possible. If you could make a CodeSandbox demonstrating what you're trying to do, it would be a lot easier to help you. - Erik R.

2 Answers

3
votes
<button
  type="button"
  onClick={() => {
      form.reset();
      this.setState({"reset": true});
  }}
  disabled={submitting || pristine}
>
    Reset
</button>

I think what you missing is executing form.reset function

0
votes

You should call the reset method instead of having form.reset:

<button
  type="button"
  onClick={() => {
    form.reset(); <-------------
    this.setState({"reset": true});
  }}
  disabled={submitting || pristine}
>
  Reset
</button>