Skip to content

Latest commit

 

History

History
 
 

repeater

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Repeater

A Repeater component that allows you to add repeater fields.

Usage

The type definition of the attribute needs to be set as an array and the name of the attribute should be passed to the attribute prop of the Repeater component.

import { Repeater } from '@10up/block-components';

export function BlockEdit(props) {
    const { attributes } = props;
    const { items } = attributes;

    return (
        <Repeater attribute="items">
            {( item, index, setItem, removeItem ) => (
                <TextControl key={index} value={item} onChange={(value) => setItem(value)} />
                <Button icon={close} label={__('Remove')} onClick={removeItem}/>
            )}
        </Repeater>
    );
}

Props

Name Type Default Description
attribute string items The name of the block attribute that holds data for the Repeater fields.
addButton function null A render prop to customize the "Add item" button.
allowReordering boolean false boolean to toggle reordering of Repeater items.