Skip to main content

Field Array

The FieldArray component enables the use of recurring fields and gives the implementer a set of tools to manage them. This component is useful when the number of fields is determined by the user and so must be dynamic.

NameTypeDefaultDescription
namestringundefinedThe name associated with the field array. The field array name will be prepended to the name of each field that it contains, along with the index of it's position in the array.
render / children(props: FieldArrayPassthroughProps) => JSX.Element;undefinedFunction that takes the current field array state and actions and returns the field components to render

Render prop args

The render prop is passed all of the fields and actions that are related to this FieldArray and should return a list of Field components to render.

Field

NameTypeDescription
namestringThe name of the field at this index. When using nested fields this name needs to be prepended to the name given to the Field itself.

Actions

NameTypeDescription
fieldsFieldArrayFieldList of details about each field along with actions to control that specific field.
push(value: any) => voidPushes the given value into the field array. This value should match the type of the fields that the field array is rendering, with any nested fields accounted for.
pop() => voidRemoves the last field from the field array
unshift(value: any) => voidInserts a new value at the start of the field array
insert(index: number, value: any) => voidInserts a new value at the specified index
replace(index: number, value: any) => voidReplaces the field at the given index with the new value
swap(index: number, otherIndex: number) => voidSwaps the position of two fields at the given indices
move(fromIndex: number, toIndex: number) => voidMoves the field from one index to another index
remove(index: number) => voidRemoves the field at the specified index