【发布时间】:2019-03-19 17:47:45
【问题描述】:
我刚开始接触本机反应,我想知道如何在返回中处理地图函数。
根据此处Using react props in .map function 给出的答案,我将我的代码修改为以下内容:
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>)
}
这是最好的方法还是可以更好地优化?
【问题讨论】:
标签: reactjs optimization native