Skip to main content

Repeater

When using a field of type repeater there is a component which lets you render each item of the repeater in an easy way. This also allows you to access each field within a repeater item via the field hooks.

Props

The hook can take an object as argument with the following properties.

FieldTypeDescription
fieldstringThe name of the repeater field
children(item: RepeaterFieldBaseData, index: number) => ReactNodeThe method to render a child

Example

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

const Item = () => {
// you can access each field within a repeater item now the same way as if it was a widget
const title = useStringField({field: 'item_title'})

return title
}

export default function Example() {
return (
<Repeater field="my_repeater_field">
{() => <Item/>}
</Repeater>
)
}