reactjsredux-formreact-admin

React-admin keep form data after create view submit


In a react-admin Create form, is there a way to keep whatever info the user typed into the form to stay on the screen after the user clicks Save?

I want to re-use the same form data that they entered to create the another record.


Solution

  • Update:

    According to this PR, it looks like react-admin clears the form state after Create / Edit Forms submission.

    Unfortunately, I didn't find out a documented way, how to prevent this default behavior.

    From the PR, I understand that passing redirect={false} and to={{ state: { skipFormReset: true } }} may prevent the form state clearing. Something like that:

    <CreateButton redirect={false} to={{ state: { skipFormReset: true } }} />
    

    Another option (a workaround) - after creation, you can try to update the current create form defaultValue with the data you already filled (created).


    Original answer: redux-form will destroy your form and its state (data) automatically when your component is unmounted.

    You can prevent this default form behaviour and keep your form's state after unmounting, as passing:

    destroyOnUnmount: false
    

    destroyOnUnmount documentation.