import React from 'react';
type Props = {
children: JSX.Element[] | JSX.Element;
margin: number;
};
export default function Stack({ children, margin }: Props) {
function wrapChildren() {
return React.Children.map(children, (child) =>
React.cloneElement(child, { style: { ...child.props.style, marginBottom: `${margin}px` } }),
);
}
return <>{wrapChildren()}</>;
}
this.props.children || props.children
<MyComponent>Hello world!</MyComponent>
<MyContainer>
<MyFirstComponent />
<MySecondComponent />
</MyContainer>