github edmundhung/conform v0.7.2

latest releases: v1.4.0, v1.3.0, v1.2.2...
2 years ago

Improvement

  • Fixed an issue when trying to reset the form after submission with a new approach (#194)
export let action = async ({ request }: ActionArgs) => {
    const formData = await request.formData();
    const submission = parse(formData, { schema });

    if (submission.intent !== 'submit' || !submission.value) {
        return json(submission);
    }

    return json({
        ...submission,
        // Notify the client to reset the form using `null`
        payload: null,
    });
};

export default function Component() {
    const lastSubmission = useActionData<typeof action>();
    const [form, { message }] = useForm({
        // The last submission should be updated regardless the submission is successful or not
        // If the submission payload is empty:
        // 1. the form will be reset automatically
        // 2. the default value of the form will also be reset if the document is reloaded (e.g. nojs)
        lastSubmission,
    })

    // ...
}

New Contributors

Full Changelog: v0.7.1...v0.7.2

Don't miss a new conform release

NewReleases is sending notifications on new releases.