rvf icon indicating copy to clipboard operation
rvf copied to clipboard

[Feature]: resetAfterSubmit="reinitialize" or something similar

Open airjp73 opened this issue 4 months ago • 1 comments

What is the new or updated feature that you are suggesting?

Originally mentioned here.

The representative use-case for this is an edit form. The flow might look something like this:

  • User edits the data in the form and submits
  • After submit, the form should be not-dirty, not-touched, not-hasBeenSubmitted, etc. But the data was updated on the backend, so the default values should be new values from the server.

Alternate solutions

Other types of APIs we might consider here are something like Formik's enableReinitialize, where simply changing the default values resets the form. Or maybe a reinitializeKey prop that reinitializes the form when the key changes.

It might also make sense not to add a new api and just document an example of how to handle this case with onSubmitSuccess + resetForm.

Why should this feature be included?

This is a super common use-case, and might be worth adding a purpose-built api.

Potential issues

This works really naturally with how react-router's submit lifecycle works, but it might not fit as nicely with a typical react-query type of setup.

airjp73 avatar Aug 28 '25 15:08 airjp73

Thanks for adding that! I would prefer an approach where I don't have to manually re-set the values in the resetForm as this would cause duplication on how we extract the default values. I think that making this is the default is simply the most logical approach as this is what I think everyone expect upon successful submission (although this probably can be considered as a breaking change).

bakura10 avatar Aug 29 '25 01:08 bakura10