javascript - React: Mapping children of a parent component - Stack Overflow

PHOTO EMBED

Fri Dec 30 2022 10:44:02 GMT+0000 (Coordinated Universal Time)

Saved by @vdgfobi #react.js

const OpaqueWrapper = ({ children }) => (
    // check that children is defined 
    // if you do not want your wrapper to be rendered empty
    children && (
        <Wrapper>
            {React.Children.map(children, child => (
                React.cloneElement(child, {style: {...child.props.style, opacity: 0.5}})
            ))}
        </Wrapper>
    )
);
content_copyCOPY

https://stackoverflow.com/questions/49496906/react-mapping-children-of-a-parent-component