I am trying to load a components inside of a Tab component for react. The Idea is have a json ( or better yaml) with this syntanx:
interface TabType {
name: string;
components: string[];
}
interface Templates {
tabs: TabType[];
}
const templateTabsModules: Templates = {
tabs: [
{
name: "Title for Tab 1",
components: ["./components/OneComponent"]
},
{
name: "Title for Tab 2",
components: ["./components/TwoComponent"]
}
]
};
So inside of the Main Component do something like:
<Tabs id="tab">
{templateTabsModules.tabs.map(tab => {
return (
<Tab title={tab.name}>
<p>The component should appears bellow:</p>
<Suspense fallback={<div>Loading</div>}>
{tab.components.map(component => {
const Comp = lazy(() => import(component));
return (<Comp />)
})}
</Suspense>
</Tab>
);
})}
</Tabs>
But this code does not work, I could see that if I use just the path as string by doing const Comp = lazy(() => import('./components/OneComponent')); it works, but does not if I use the dynamic variable.