safe-action-forms

Integrates next-safe-action server actions with native HTML forms and react-hook-form.

Updated Jul 8, 2026
One-click install
npx skills add https://github.com/NarixHine/uni-chem --skill safe-action-forms-narixhine
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: safe-action-forms
Source: https://github.com/NarixHine/uni-chem/tree/main/.agents/skills/safe-action-forms
Command: npx skills add https://github.com/NarixHine/uni-chem --skill safe-action-forms-narixhine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires next-safe-action, @next-safe-action/adapter-react-hook-form, react-hook-form, @hookform/resolvers, zod, zod-form-data.

What problem does it solve? Wiring type-safe server actions into forms requires manually bridging validation errors, pending states, and submission handlers. This Skill provides ready-made patterns for connecting next-safe-action to native HTML forms, useStateAction form actions, and react-hook-form, including file uploads and bound arguments. ## Core Features & Use Cases - Multiple Integration Approaches: Choose between useAction with native forms, useStateAction with <form action={formAction}>, or the react-hook-form adapter (useHookFormAction, useHookFormOptimisticAction) based on form complexity. - Automatic Error Mapping: Server-side Zod validationErrors are mapped to react-hook-form's FieldErrors format via mapToHookFormErrors, including root-level errors. - File Uploads: Validate and upload single or multiple files using zod-form-data schemas, with size and MIME-type refinement, optionally combined with bind arguments. - Use Case: Build a profile edit form where the server action validates input with Zod, the client uses useStateAction to access prevResult, and field-level validation errors render inline next to each input. ## Quick Start Ask the AI to create a contact form using next-safe-action's useHookFormAction with a Zod schema for name, email, and message fields.

Frequently Asked Questions about safe-action-forms

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use next-safe-action with react-hook-form?▼

Use useHookFormAction from @next-safe-action/adapter-react-hook-form/hooks, passing your safe action and zodResolver(schema). It returns form, action, and handleSubmitWithAction, which you attach to the form's onSubmit. Server validationErrors are automatically mapped to react-hook-form field errors.

When should I use useStateAction vs useAction for forms?▼

Use useAction with onSubmit and e.preventDefault() for simple forms and programmatic triggers. Use useStateAction with <form action={formAction}> when you need the server to receive prevResult, such as stateful forms or multi-step wizards. Note that useStateAction requires the action to be defined with .stateAction().

How do I handle file uploads with next-safe-action?▼

Use zod-form-data to define a schema with zfd.file() and refinements for size and MIME type, then pass FormData directly to execute on the client. Multiple files are supported via zfd.repeatableOfType, and file uploads can be combined with bind arguments like a post ID.

How are server validation errors mapped to react-hook-form?▼

The adapter converts next-safe-action's nested validationErrors shape (e.g., { email: { _errors: [...] } }) into react-hook-form's FieldErrors format using mapToHookFormErrors. Multiple messages per field are joined with a configurable separator, and root-level errors map to the root key.

Can I pass extra arguments not present in the form to a server action?▼

Yes, define .bindArgsSchemas() on the action (e.g., a UUID for a postId), then call action.bind(null, postId) on the client before passing it to useAction. The bound values arrive in the handler as bindArgsParsedInputs alongside parsedInput.