# rn-schema-repeater URL: /docs/native/docyrus/schema-repeater A generic repeater component for managing dynamic lists of items with reordering, adding, and removing capabilities. ## Installation ```bash pnpm dlx @docyrus/cli add @docyrus/rn-schema-repeater ``` ## Usage ```tsx import { SchemaRepeater } from '@/components/docyrus-native/schema-repeater'; type LineItem = { id: string; name: string; quantity: number }; value={items} onValueChange={setItems} createItem={() => ({ id: String(Date.now()), name: '', quantity: 1 })} renderItem={(item, index, helpers) => ( helpers.update({ name: text })} /> )} /> ``` ## API Reference ### SchemaRepeaterProps\ | Prop | Type | Default | Description | |------|------|---------|-------------| | `value` | `T[]` | — | Array of items to render. Each item must have an `id: string` field | | `onValueChange` | `(items: T[]) => void` | — | Called when items are added, removed, reordered, or updated | | `renderItem` | `(item: T, index: number, helpers: SchemaRepeaterHelpers) => ReactNode` | — | Render function for each item. Receives the item, its index, and helper functions | | `createItem` | `() => T` | — | Factory function to create a new item when the add button is pressed | | `maxItems` | `number` | — | Maximum number of items allowed. Add button hides when reached | | `minItems` | `number` | `0` | Minimum number of items required. Remove button disables when reached | | `addLabel` | `string` | `ui.schemaRepeater.add` (“Add”) | Label text for the add button | | `disabled` | `boolean` | `false` | Disables all interactions including add, remove, and reorder | | `className` | `string` | — | Additional CSS classes | ### SchemaRepeaterItem | Field | Type | Description | |-------|------|-------------| | `id` | `string` | Unique identifier required for each item | ### SchemaRepeaterHelpers\ | Field | Type | Description | |-------|------|-------------| | `remove` | `() => void` | Removes the current item | | `update` | `(updates: Partial) => void` | Partially updates the current item | | `moveUp` | `() => void` | Moves the current item up by one position | | `moveDown` | `() => void` | Moves the current item down by one position | | `isFirst` | `boolean` | Whether this is the first item in the list | | `isLast` | `boolean` | Whether this is the last item in the list | ## Form field variant `field-schemaRepeater` forms use `DocyFieldSchemaRepeater` from `@docyrus/rn-form-fields` — rows of IField sub-fields rendered through `DocyFieldDynamic` (schema mode) or key / value pairs, with move up / down, duplicate and collapsible rows. See [Form Fields](/docs/native/docyrus/form-fields#docyfieldschemarepeater). ## Type Exports | Type | Description | |------|-------------| | `SchemaRepeaterProps` | Props for SchemaRepeater component | | `SchemaRepeaterItem` | Base interface for repeater items (requires `id`) | | `SchemaRepeaterHelpers` | Helper object passed to renderItem callback |