I have a question about rendering components from object map. I have a structure like this:
const tabs = [
'tab1': {
name: 'Tab 1',
renderComponent: () => <Tab1Component />
},
'tab2': {
name: 'Tab 2',
renderComponent: () => <Tab2Component />
}
];
I want to access the renderComponent property and render sub component. Tried with function invocation, React.createElement(), doesn't work.
const MyComponent = ({tabs}) => {
const activeTab = 'tab1';
return (
<>
// How to render it?
// function invocation?
// createElement??
tabs[activeTab].renderComponent();
</>
);
};
{ tabs[activeTab].renderComponent() }