useArrayField()

useArrayField hook handles state and manipulation of an array form field.

Provider required

FormProvider is required in order to use this hook

function useArrayField(fieldPath: string): ArrayField;

Field path

The dot notation path of the array field (e.g. user.todos)

ArrayField

Contains the array field value, along with other useful details and array manipulation methods.

interface ArrayField<ItemValue> {
initialValue?: ItemValue[];
value?: ItemValue[];
error?: FieldError;
isDirty: boolean;
set: (array: ItemValue[]) => void;
reset: () => void;
dismissError: () => void;
append: (value: ItemValue) => void;
swap: (indexA: number, indexB: number) => void;
move: (from: number, to: number) => void;
insert: (index: number, value: ItemValue) => void;
prepend: (value: ItemValue) => void;
remove: (index: number) => void;
replace: (index: number, value: ItemValue) => void;
}

initialValue

ItemValue[];

value

ItemValue[];

error

FieldError

isDirty

boolean;

set

(array: ItemValue[]) => void;

Replace the entire array

reset

() => void

dismissError

() => void

append

(value: ItemValue) => void

swap

(indexA: number, indexB: number) => void

move

(from: number, to: number) => void

insert

(index: number, value: ItemValue) => void

prepend

(value: ItemValue) => void

remove

(index: number) => void

replace

(index: number, value: ItemValue) => void