【发布时间】:2019-06-29 03:28:44
【问题描述】:
我有一个项目列表,每个项目都有一个正文和一个来源。目前它呈现如下:
const ListItem = (props) => {
const {body, source} = props.context;
return (
<View style={styles.item}>>
<View style={{backgroundColor: 'lightblue'}}>
<Text style={styles.body}>{body}</Text>
</View>
<View style={{backgroundColor: 'lightyellow'}}>
<Text style={styles.source}>{source}</Text>
</View>
</View>
);
}
这是很多嵌套和容器。能不能做得更优化?
【问题讨论】:
-
我想这取决于你的设计,AFAIK 这在 React Native 中很好,前提是你正在使用优化的方式来呈现你的列表(例如,使用 FlatList 或类似的)
-
@Dan 所有外部优化,如 FlatList 都已到位。我只是好奇有没有办法跳过如此可怕的视图树或者可以这样做。
标签: performance react-native dom optimization