Skip to main content

Function: useBindFormField()

useBindFormField<T>(fieldPath, fallBackPath?, fallbackValue?, subscribe?): object

Defined in: hooks/useBindFormField.ts:39

Hook to bind a form field with optional fallback path synchronization. This hook is similar to useFormField but allows binding a field to a fallback path, useful for creating field aliases or synchronized fields.

Type Parameters

T

T

The type of the field value

Parameters

fieldPath

string

Primary dot notation path to the field

fallBackPath?

string

Optional fallback path to synchronize with

fallbackValue?

T

Default value to use if field is undefined

subscribe?

boolean

Whether to subscribe to real-time value changes (default: true)

Returns

object

Object containing field value, error state, and control methods

value

value: undefined | T

error

error: undefined | string

errors

errors: undefined | ValidationError[]

isTouched

isTouched: boolean

validate()

validate: () => void

Returns

void

touch()

touch: (fieldName) => void

Parameters

fieldName

string

Returns

void

setValue()

setValue: (newValue) => void = handleSetValue

Parameters

newValue

T

Returns

void

Example

const NameField = () => {
const { value, error, setValue } = useBindFormField<string>(
'user.name',
'displayName', // Also update displayName when user.name changes
''
);

return (
<input
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
};