【问题标题】:A question about FlatList renderItem Component performance and memory usage关于 FlatList renderItem 组件性能和内存使用的问题
【发布时间】:2018-10-10 21:47:56
【问题描述】:

我是react-native 新手。 只是关于FlatListrenderItemComponent 性能和内存使用的问题。

renderItemComponents 下面哪个性能更快,哪个对大型列表内存友好?

1:

class MyListItem extends React.PureComponent {
  render() {
    return (
     <View style={{width: '100%', height: 60}}>
       {
         this.props.size ===  30 ?
         (
           <View style={{width: 30, height: 30}}>
                <Text>test</Text>
           </View>
         )
         :
         null
       }
       <View>...</View>
     </View>
    )
  }
}

2:

class MyListItem extends React.PureComponent {
  render() {
    return (
         <View style={{width: '100%', height: 60}}>
           <View style={{width: this.props.size, height: this.props.size}}>
                <Text>test</Text>
           </View>
           <View>...</View>
         </View>
    )
  }
}

谢谢。

【问题讨论】:

    标签: react-native react-native-flatlist


    【解决方案1】:

    Second 更快且内存友好,因为它不会检查任何条件,因此与 First 相比,它的性能更快。 你可以使用 FlatList 比两者都好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多