react-final-formfinal-form

Reset form without losing submitSucceeded


When using React Final Form, is there a way to reset the form without losing the submitSucceeded state. I want to display a success message on the form but I also want to clear it after a successful submit.


Solution

  • reset() clears all state. You could either:

    a) Notice when submitSucceeded becomes true and save that state locally with setState(), or

    b) Clear each field manually, with something like:

    form.batch(() => {
      form.change('firstField', '')
      form.change('secondField', '')
      form.change('thirdField', '')
      // ...
    }) 
    

    Neither is incredibly elegant, but...