### Install Conform with Valibot Source: https://github.com/edmundhung/conform/blob/main/docs/installation.md Install Conform, the React helper, and the Valibot validation library using npm. ```bash npm install @conform-to/react @conform-to/valibot valibot ``` -------------------------------- ### Install Conform with Yup Source: https://github.com/edmundhung/conform/blob/main/docs/installation.md Install Conform, the React helper, and the Yup validation library using npm. ```bash npm install @conform-to/react @conform-to/yup yup ``` -------------------------------- ### Install Conform with Zod Source: https://github.com/edmundhung/conform/blob/main/docs/installation.md Install Conform, the React helper, and the Zod validation library using npm. ```bash npm install @conform-to/react @conform-to/zod zod ``` -------------------------------- ### Install Conform with Zod, Valibot, or Yup Source: https://context7.com/edmundhung/conform/llms.txt Install the core `@conform-to/react` package along with the appropriate schema adapter for Zod, Valibot, or Yup. ```bash # With Zod v3 npm install @conform-to/react @conform-to/zod zod # With Zod v4 npm install @conform-to/react @conform-to/zod zod # With Valibot npm install @conform-to/react @conform-to/valibot valibot # With Yup npm install @conform-to/react @conform-to/yup yup ``` -------------------------------- ### Install Conform and Zod Integration Source: https://github.com/edmundhung/conform/blob/main/docs/tutorial.md Install the necessary Conform packages for React and Zod integration using npm. ```sh npm install @conform-to/react @conform-to/zod --save ``` -------------------------------- ### Example Usage Source: https://github.com/edmundhung/conform/blob/main/docs/api/react/getInputProps.md Demonstrates how to use getInputProps with a password input field. ```APIDOC ## Example ```tsx import { useForm, getInputProps } from '@conform-to/react'; function Example() { const [form, fields] = useForm(); return ; } ``` ``` -------------------------------- ### Get Collection Props Source: https://github.com/edmundhung/conform/blob/main/docs/api/react/getCollectionProps.md A basic example demonstrating how to use `getCollectionProps` to generate props for a collection of radio buttons. ```tsx import { useForm, getCollectionProps } from '@conform-to/react'; function Example() { const [form, fields] = useForm(); return ( <> {getCollectionProps(fields.color, { type: 'radio', options: ['red', 'green', 'blue'], }).map((props) => ( ))} ); } ``` -------------------------------- ### Basic Usage Example Source: https://github.com/edmundhung/conform/blob/main/docs/api/zod/parseWithZod.md An example demonstrating how to use parseWithZod within a React component's form validation. ```APIDOC ## Example ```tsx import { useForm } from '@conform-to/react'; import { parseWithZod } from '@conform-to/zod'; // If you are using Zod v4, update the imports: // import { parseWithZod } from '@conform-to/zod/v4'; import { z } from 'zod'; const schema = z.object({ email: z.string().email(), password: z.string(), }); function Example() { const [form, fields] = useForm({ onValidate({ formData }) { return parseWithZod(formData, { schema }); }, }); // ... } ``` ``` -------------------------------- ### Example Usage Source: https://github.com/edmundhung/conform/blob/main/docs/api/react/useInputControl.md Demonstrates how to use the `useInputControl` hook with a custom select component to manage input value and events. ```APIDOC ## Example ```tsx import { useForm, useInputControl } from '@conform-to/react'; import { Select, Option } from './custom-ui'; function Example() { const [form, fields] = useForm(); const color = useInputControl(fields.color); return ( ); } ``` ``` -------------------------------- ### Complete Form Example with Zod Validation and Submission Source: https://github.com/edmundhung/conform/blob/main/docs/tutorial.md A full example demonstrating Conform integration with Zod for schema definition, validation, and form submission handling in a Remix application. It includes input props generation and error display. ```tsx import { useForm, getFormProps, getInputProps, getTextareaProps, } from '@conform-to/react'; import { parseWithZod, getZodConstraint } from '@conform-to/zod'; import { type ActionFunctionArgs } from '@remix-run/node'; import { Form, useActionData } from '@remix-run/react'; import { z } from 'zod'; import { sendMessage } from '~/message'; const schema = z.object({ email: z.string({ required_error: 'Email is required' }) .email('Email is invalid'), message: z.string({ required_error: 'Message is required' }) .min(10, 'Message is too short') .max(100, 'Message is too long'), }); export async function action({ request }: ActionFunctionArgs) { const formData = await request.formData(); const submission = parseWithZod(formData, { schema }); if (submission.status !== 'success') { return submission.reply(); } const message = await sendMessage(submission.value); if (!message.sent) { return submission.reply({ formErrors: ['Failed to send the message. Please try again later.'], }); } return redirect('/messages'); } export default function ContactUs() { const lastResult = useActionData(); const [form, fields] = useForm({ lastResult, constraint: getZodConstraint(schema), shouldValidate: 'onBlur', shouldRevalidate: 'onInput', onValidate({ formData }) { return parseWithZod(formData, { schema }); }, }); return (
{fields.email.errors}