Docs Menu
Docs/Recipes/Form Submission with Promise Feedback
Updated October 2026

Form Submission with Promise Feedback

Provide clear asynchronous status feedback during form validation, serialization, and network dispatch.

Combine form submission states with toast.promise() to give users immediate visual assurance during database mutations.

tsx
import React, { useState } from 'react';

export function ContactForm() { const [submitting, setSubmitting] = useState(false);

const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); const formData = new FormData(e.currentTarget); setSubmitting(true);

try { await toast.promise( fetch('/api/contact', { method: 'POST', body: formData }).then((r) => { if (!r.ok) throw new Error('Submission failed'); return r.json(); }), { loading: 'Sending message...', success: 'Message delivered! We will reply within 24 hours.', error: (err) => Failed: ${(err as Error).message}, description: 'Secure TLS dispatch to customer support.', } ).unwrap(); e.currentTarget.reset(); } finally { setSubmitting(false); } };

return (