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()}</>;
}
<MyComponent>Hello world!</MyComponent>
<MyContainer>
<MyFirstComponent />
<MySecondComponent />
</MyContainer>