I create a component which is a parent component of another: Container is parent and Container.Data children. In this way I can add a structure to my component.
const Container = ({ children }) => {
return (
<div>
<h1>Container</h1>
{children}
</div>
);
};
const Data = ({ children }) => {
return <div>{children}</div>;
};
Container.Data = Data;
export { Container };
///
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<Container>
<Container.Data>item1</Container.Data>
<Container.Data>item2</Container.Data>
</Container>
<Container.Data>item3</Container.Data>
</div>
The issue is next: <Container.Data>item3</Container.Data> is outside the component and it works, but I want in the case when I will add the <Container.Data>item3</Container.Data> outside the parent Container, to get an error. So all items should be only inside Container.
Question: How to do this?
demo: https://codesandbox.io/s/stupefied-dubinsky-6lh8v?file=/src/Container.js:27-264