Function: useField
▸ Const useField<T, E, W>(path, form?): [FieldData<T, unknown, unknown>, Field<T, unknown, unknown>]
The useField hook binds a Field instance to the branch of the form value state at path and subscribes to its state changes as local component state.
Type parameters#
| Name | Type | Description |
|---|---|---|
T | unknown | Field value type. jsx const ConnectedField = () => { const [state, field] = useField('fieldPath'); return ( <input value={state.value} onFocus={() => field.focus()} onBlur={() => field.blur()} onChange={(event) => field.setValue(event.target.value)} /> ); } |
E | unknown | - |
W | unknown | - |
Parameters#
| Name | Type |
|---|---|
path | FieldPath |
form | FormState<any, any, any, any> |
Returns#
[FieldData<T, unknown, unknown>, Field<T, unknown, unknown>]