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.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | undefined | The 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; | undefined | Function 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
| Name | Type | Description |
|---|---|---|
name | string | The 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
| Name | Type | Description |
|---|---|---|
fields | FieldArrayField | List of details about each field along with actions to control that specific field. |
push | (value: any) => void | Pushes 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 | () => void | Removes the last field from the field array |
unshift | (value: any) => void | Inserts a new value at the start of the field array |
insert | (index: number, value: any) => void | Inserts a new value at the specified index |
replace | (index: number, value: any) => void | Replaces the field at the given index with the new value |
swap | (index: number, otherIndex: number) => void | Swaps the position of two fields at the given indices |
move | (fromIndex: number, toIndex: number) => void | Moves the field from one index to another index |
remove | (index: number) => void | Removes the field at the specified index |