I just started getting into react native and I was wondering on how to treat map functions within the return.
Based on the answer given here Using react props in .map function I adapted my code as its following:
render()
{
const { active } = this.state
const drawerContent = Object.keys(drawerItems).map(section => {
return <DrawerComponent.Section key={section.toLowerCase()} title={section} style={styles.section}>
{drawerItems[section].map(item =>
<DrawerComponent.Item
key={item.id}
label={item.label}
icon={item.icon}
style={styles.item}
active={active === item.id}
onPress={() => nav.push(item.screen + 'Screen', item.props || {})}
/>
)}
</DrawerComponent.Section>
})
return(<View style={styles.container}>{drawerContent}</View>)
}
Is this the best approach or can anything be better optimized?