In my React Native app, I have a custom tab control that is rendered dynamically using the following configuration:
const TABS = [
{ title: 'Tab 1', component: MyComponentOne },
{ title: 'Tab 2', component: MyComponentTwo }
];
The title
property is used for the tab title, and when a tab is selected, I want to render the corresponding component inside an Animated.FlatList
.
Is there a way for me to dynamically render MyComponentOne
and MyComponentTwo
, instead of having to do this manually?:
if (typeof item.component === 'MyComponentOne') return <MyComponentOne />
if (typeof item.component === 'MyComponentTwo') return <MyComponentTwo />
Any suggestions on how to achieve this?