useHtmlField
React custom hook for connecting an <input>
element to form state.
import { useHtmlField } from '@jcoreio/zod-forms'
export function useHtmlField({ field, type, normalizeOnBlur }): UseHtmlFieldProps`
The full method signature extracts the type of the subschema at the given path, and should produce a
TS error if the path is invalid, doesn't exist in the schema, or its subschema doesn't accept
string | number | bigint | boolean | null | undefined
.
Options
field
- aFieldPath
. If you castuseHtmlField
toTypedUseArrayField
or use theuseHtmlField
returned fromcreateZodForm
,path
may be a pathstring or path array.type
- thetype
attribute for the<input>
elementnormalizeOnBlur
(optional, defaults totrue
) - whether to normalize the displayed value on blur
Returns UseHtmlFieldProps
An object containing the following properties. Causes a rerender when any of these properties changes.
input
-HtmlFieldInputProps
to pass to an<input>
element:name
- the name of the field (the pathstring of the field path)type
- thetype
from the optionsvalue
- the value to displaychecked
- include iftype
is"checkbox"
onChange
- the change event handleronFocus
- the focus event handleronBlur
- the blur event handler
meta
- theUseFieldProps
for the field