useArrayField

useArrayField is the hook for array field components. Under the hood, it combines RHF's useFieldArray with the same field metadata layer as useField — giving array components access to both mutation methods and resolved field props in one place.

const { label, errorMessage, items, renderItems, append, ... } = useArrayField()

Field props

The same field props as useField are available directly, scoped to the array field itself — not individual items:

PropDescriptionNotes
labelTranslated labelResolved from field config through i18n pipeline
descriptionTranslated helper textResolved from field config through i18n pipeline
errorMessageArray-level validation errore.g. from rules.minLength or rules.required — not item errors
requiredWhether the array is requiredDerived from rules.required
disabledWhether the array is disabledResolved for UI logic; does not by itself remove the array from submit payload
visibleWhether the array should renderWhen false, the array field unmounts; see conditional rendering

Array state

PropDescriptionNotes
itemsCurrent list of array itemsAlias of fields from RHF's useFieldArray — use item.id as React key
renderItem(field, index)Render a single itemScoped automatically to the correct namespace (e.g. addresses.0)
renderItems()Render all itemsShorthand for items.map(renderItem)

Array methods

RHF's useFieldArray methods, forwarded as-is:

MethodDescription
append(value)Add item at the end
prepend(value)Add item at the beginning
insert(index, value)Add item at a specific position
remove(index?)Remove item by index, or all items if omitted
update(index, value)Replace item at index
move(from, to)Move item to a new position
swap(a, b)Swap two items
replace(values)Replace the entire list

Convenience helpers added by BlueForm:

HelperDescriptionNotes
push(value)Add item at the endAlias of append
pop()Remove the last itemNo-op when array is empty
clear()Remove all itemsEquivalent to remove() with no index
duplicate(index)Append a copy of the item at indexUses current form values — reflects user edits. No-op when index does not exist
idAt(index)Stable key for the itemUse as React key — falls back to index if RHF id is unavailable
errorAt(index)Validation error subtree for item at indexUseful for highlighting collapsed items with errors

Complete example

addresses: {
  type: "array",
  label: "Addresses",
  rules: {
    minLength: { value: 2, message: "At least 2 addresses required" },
  },
  props: {
    config: defineConfig<Address>({
      street: { type: "text", label: "Street" },
      city: { type: "text", label: "City" },
      country: { type: "text", label: "Country" },
    }),
  },
  render: () => {
    const { items, renderItems, append, duplicate, pop, clear, label, errorMessage } = useArrayField()

    return (
      <fieldset>
        <legend>{label}</legend>

        {renderItems()}

        <div>
          <button
            type="button"
            onClick={() => append({ street: "", city: "", country: "" })}
          >
            Add
          </button>
          <button
            type="button"
            disabled={!items.length}
            onClick={() => duplicate(items.length - 1)}
          >
            Duplicate last
          </button>
          <button
            type="button"
            disabled={!items.length}
            onClick={pop}
          >
            Remove last
          </button>
          <button
            type="button"
            disabled={!items.length}
            onClick={clear}
          >
            Clear all
          </button>
        </div>

        {errorMessage && <div>{errorMessage}</div>}
      </fieldset>
    )
  },
}