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, fields, 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 is visibleAlways true here: a hidden array is not rendered; see conditional rendering

Array state

PropDescriptionNotes
fieldsCurrent list of array itemsFrom RHF's useFieldArray — use field.id as React key. items is a deprecated alias (removed in 1.0)
renderItem(field, index)Render a single itemScoped automatically to the correct namespace (e.g. addresses.0)
renderItems()Render all itemsShorthand for fields.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)Deprecated alias of appendRemoved in 1.0
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" },
    }),
  },
  // everything useArrayField() returns arrives as the render argument
  render: ({ fields, renderItems, append, duplicate, pop, clear, label, errorMessage }) => {
    return (
      <fieldset>
        <legend>{label}</legend>

        {renderItems()}

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

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