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 castuseHtmlFieldtoTypedUseArrayFieldor use theuseHtmlFieldreturned fromcreateZodForm,pathmay be a pathstring or path array.type- thetypeattribute 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-HtmlFieldInputPropsto pass to an<input>element:name- the name of the field (the pathstring of the field path)type- thetypefrom the optionsvalue- the value to displaychecked- include iftypeis"checkbox"onChange- the change event handleronFocus- the focus event handleronBlur- the blur event handler
meta- theUseFieldPropsfor the field