I'm trying to make a React Component with Subcomponents in the style of: https://react-bootstrap.github.io/components/cards/ which should render one component on the left and one on the right
<MyComponent>
<MyComponent.Left>
foo
</MyComponent.Left>
<MyComponent.Right>
bar
</MyComponent.Right>
</MyComponent>
My basic strategy has been to create something like this:
function MyComponent(props:PropsWithChildren):JSX.Element{
var leftComponent = ???;
var rightComponent = ???;
return
(<div>
<div className="this-goes-on-the-right">leftComponent</div>
<div className="this-goes-on-the-left">rightComponent</div>
</div>);
}
function MyComponent.Left = function MyComponentLeft(props:PropsWithChildren){
return (<div>props.children</div>);
}
function MyComponent.Right = function MyComponentRight(props:PropsWithChildren){
return (<div>props.children</div>);
}
But I'm lost as to how to figure out which of the children passed to MyComponent is the MyComponent.Left and which is the MyComponent.Right. How can I do this in typescript?
They are using
Object.assign
to assign "sub components".Source