--- name: safe-action-forms description: Use when integrating next-safe-action with forms -- react-hook-form adapter (useHookFormAction, useHookFormOptimisticAction, mapToHookFormErrors), native HTML forms, bind arguments, or file uploads --- # next-safe-action Form Integration ## Options | Approach | When to Use | |---|---| | `useAction` + native form | Simple forms, no complex validation UI | | `useHookFormAction` (RHF adapter) | Complex forms with field-level errors, validation on change/blur | | `useHookFormOptimisticAction` | RHF forms with optimistic UI updates | ## Quick Start — Native Form ```tsx "use client"; import { useAction } from "next-safe-action/hooks"; import { submitContact } from "@/app/actions"; export function ContactForm() { const { execute, result, isPending } = useAction(submitContact); return (
{ e.preventDefault(); const fd = new FormData(e.currentTarget); execute({ name: fd.get("name") as string, email: fd.get("email") as string, message: fd.get("message") as string, }); }} >