Skip to main content

useRepeaterField

Reads the raw values of all items of a repeater field.

function useRepeaterField<T extends Record<string, unknown>>(props: {field: string}): T[]
tip

To render the items of a repeater, use the Repeater component instead. Within each item, it allows reading the item's fields using the field hooks, including metrics.

Arguments​

PropertyTypeDescription
fieldstringThe name of the field.

Returns​

An array with one object per item. Each object contains the raw values of the item's fields by their name. Fields without a value may be missing. An empty array if the repeater has no items.

Example​

src/widgets/example/Example.tsx
import React from 'react'
import {useRepeaterField} from '@modbros/dashboard-sdk'

type ExampleRepeaterItem = {
title?: string
limit?: number
}

export default function Example() {
const items = useRepeaterField<ExampleRepeaterItem>({field: 'example'})

return (
<ul>
{items.map((item, index) => (
<li key={index}>
{item.title}: {item.limit}
</li>
))}
</ul>
)
}

Declare the item with type instead of interface: interfaces don't satisfy the Record<string, unknown> constraint.