Skip to content

Files

Latest commit

ecdee1f · Dec 3, 2024

History

History

optional

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jun 18, 2024
Dec 3, 2024

Optional

Optional Component Demo

A component that takes care of the logic of rendering nodes only when it is selected.

Usage

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

const BlockEdit = (props) => {
    const { attributes, setAttributes, isSelected } = props;
    const { title } = attributes;

    const blockProps = useBlockProps();

    return (
        <div {...blockProps}>
            <Optional value={ title }>
                <RichText tagName="h2" value={ title } onChange={ value => setAttributes({ title: value }) } />
           </Optional>
        </div>
    )
}

The <RichText> node will only render when BlockEdit is selected.

Props

Name Type Default Description
value string '' The value that will be consumed by the children. If the value is falsy the component will only be rendered if the block is selected.