@piplup/rhf-coreComponents
FormContainer
Wires up the form element, FormProvider and FormErrorProvider components together in a single component.
Import
import { FormContainer } from '@piplup/rhf-core';Usage
Basic usage with FormContainer. It accepts the same options you would normally pass to useForm (for example: defaultValues, resolver, etc.) and handles form registration and submission wiring for you.
'use client';import { HtmlFormHelperTextElement, HtmlFormLabelElement, HtmlInputElement,} from '@piplup/rhf-adapters/html';import { FormContainer } from '@piplup/rhf-core';export default function Page() { return ( <FormContainer defaultValues={{ name: '' }} onSubmit={(values) => alert(JSON.stringify(values, null, 2))} > <div> <HtmlFormLabelElement htmlFor="name" name="name"> Name </HtmlFormLabelElement> <HtmlInputElement className="border px-2 block rounded" id="name" name="name" placeholder="Type your name" required /> <HtmlFormHelperTextElement style={({ error }) => ({ ...(error && { color: 'red' }), })} name="name" renderOnError /> </div> <button className="bg-black hover:bg-black/90 px-4 py-1 text-white rounded mt-3" type="submit" > Submit </button> </FormContainer> );}Props
Prop
Type
FormContainer forwards refs to the underlying <form> element and exposes the onSubmit prop for reading the submitted form data.
Notes
- Use
useFormContext()inside nested components to accessregister,watch,setValue, etc. - You can pass any options accepted by
useFormdirectly toFormContainerorformContextreturned byuseFormhook. - Because
FormContainerrenders a native<form>withnoValidateprop, therefore, browser-level validations are ignored unless explicitly enabled.