Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rijvi-mahmud/shaddy/llms.txt
Use this file to discover all available pages before exploring further.
ShaddyForm is the core component of the Shaddy Form system. It initializes a react-hook-form instance, applies a Zod resolver for schema-based validation, provides the form context to all descendant Field components, and renders a standard <form> element that calls your onSubmit handler only after all validations pass.
Installation
TypeScript Types
ShaddyForm is built around two exported types.
ShaddyFormProps<TSchema>
<form> attributes (such as className, id, style) are accepted and forwarded to the underlying <form> element. The native onSubmit is omitted and replaced by the typed onSubmit prop.
ShaddyFormRef<T>
ref to ShaddyForm, the ref handle exposes the full UseFormReturn object — giving you access to getValues, setValue, trigger, reset, formState, and every other method from react-hook-form.
Props
A Zod schema that defines the shape and validation rules of the form. The schema’s inferred type becomes the generic type
TSchema used throughout the form — in initialValues, the onSubmit callback, and all Field component name props.The starting values for every field in the form. The type is inferred from
TSchema, so TypeScript will catch any missing or mistyped keys at compile time.A callback invoked only after all Zod validations pass. Receives the validated form data typed as
TSchema. Any async logic (API calls, navigation) can be performed here.The content of the form. Typically a layout containing Field components (e.g.,
TextField, PasswordField) and action buttons (SubmitButton, ResetButton). All children have access to the form context automatically.Controls when
react-hook-form runs field validation:"onChange"— validates as the user types (default)."onBlur"— validates when the field loses focus."onSubmit"— validates only when the form is submitted."all"— validates on all events.
An optional ref for accessing the
react-hook-form instance (UseFormReturn) from outside the component tree. Useful for multi-step forms or components that need to programmatically read, set, or trigger validation on form fields.All other standard HTML
<form> attributes (className, id, style, aria-*, etc.) are forwarded directly to the underlying <form> element.Basic Usage
Using the ref to Access the Form Externally
For advanced scenarios — such as multi-step forms, external reset buttons, or reading form values from a parent component — attach a ref to ShaddyForm to obtain the UseFormReturn instance.
The
ref exposes the complete react-hook-form UseFormReturn API. This includes setValue, setError, clearErrors, trigger, watch, getValues, reset, and the full formState object.Validation Modes
Choose themode that best fits your user experience:
| Mode | When validation runs |
|---|---|
"onChange" (default) | On every keystroke — immediate feedback |
"onBlur" | When a field loses focus — less disruptive |
"onSubmit" | Only when the user attempts to submit |
"all" | On every event — maximum feedback |