Skip to content

useForm - reset the form in onSucces shows unexpected behavior #2411

@thoresuenert

Description

@thoresuenert

Version:

  • @inertiajs/react version: 2.0.11

Describe the problem:

I have a create form in a sheet which stays mounted after submit, i manage open/close state manually for different purposes.
After Submit in onSuccess i want to reset the form to the initial provided defaults (clear the form), but the default behavior is an overwrite of the defaults to the submitted data of the form.
This behavior makes totally sense because most of the time an edit form stays on the page and a create form redirect to the new data.

To opt out i provide a form.reset() in the onSuccess callback to reset the form, but the hook runs to late.

Steps to reproduce:

let form = useForm({ default: 'value'});

form.post('/some-url', {
 onSuccess: (page) => form.reset();
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    reactRelated to the react adapter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions