So I came across some interesting code and I was wondering if its possible to "sugarize" it.
The components come as:
const sections = {
Home: dynamic(() => import("./Sections/Home")),
Example: dynamic(() => import("./Sections/Example")),
};
And then they are being rendered as:
export default function Page({ page }) {
return (
<main>
{page.sections.map((section, index) => {
const SectionComponent = sections[section.type] || null;
return (
<SectionComponent
key={`${pageKey}-${index}`}
id={index}
fields={section.fields}
/>
);
})}
</main>
);
}
So what would be the syntax to directly render
sections[section.type]({id: index, fields: section.fields})
to do something like this within the map, to reduce the code, without the SectionComponent variable in between?