claus / storyblok-rich-text-react-renderer

A React renderer for Storyblok rich text content
MIT License
87 stars 16 forks source link

Detecting first child #37

Closed davshoward closed 1 year ago

davshoward commented 1 year ago

Hey, love the plugin.

Was wondering if there was any way of detecting whether an element is the "first" child or not?

Specifically for the use case of a heading to be able to do something like this:

[NODE_HEADING]: (children, props) => {
    const { level } = props;
    const isFirstChild = ???;

    return (
        <H {...level} spacing={isFirstChild ? 'b' : 'y'}>
            {children}
        </H>
    );
}

Cheers

claus commented 1 year ago

No that's not possible, unfortunately. I don't know what your spacing prop does, but maybe CSS can help? (:first-child or :first-of-type)

davshoward commented 1 year ago

No worries :-)