useField()
useField
hook handles state and manipulation of a form field.
Provider required
FormProvider
is required in order to use this hook
Array fields
For array fields use useArrayField
instead.
function useField(options: string | FieldConfig): Field;
Field config
interface FieldConfig<FieldValue> {
name: string;
type?: string;
/** Used for checkboxes */
value?: FieldValue;
}
name
TBD
type
TBD
value
TBD
Field
Contains the field value along with other useful field details and methods.
interface Field<FieldValue> {
initialValue: FieldValue;
value: FieldValue;
error?: FieldError;
setValue: (newValue: FieldValue) => void;
setTouched: (touched?: boolean) => void;
reset: () => void;
dismissError: () => void;
isTouched: boolean;
isDirty: boolean;
props: FieldProps;
}
initialValue
FieldValue;
value
FieldValue;
error
FieldError;
setValue
(newvalue: fieldvalue) => void
setTouched
(touched?: boolean) => void
reset
() => void
dismissError
() => void
isTouched
boolean;
isDirty
boolean;
props
interface FieldProps {
name: string;
type?: string;
onChange(event: React.ChangeEvent<HTMLInputElement>): void;
onChange(value: any): void;
onBlur: (event?: React.FocusEvent<HTMLElement>) => void;
value?: string | number;
checked?: boolean;
}