有关FlatList renderItem组件性能和内存使用的问题

时间:2018-10-10 21:47:57

标签: react-native react-native-flatlist

我是react-native新手。 只是有关FlatList renderItem Component性能和内存使用的问题。

renderItem Component以下的哪个中,性能更快,并且对于较大的列表而言,哪一个对内存友好?

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>
    )
  }
}

谢谢。

1 个答案:

答案 0 :(得分:0)

Second第二个速度更快并且对内存友好,因为它不会检查任何条件,因此与first相比,它的性能更快。  您可以使用FlatList,这比两者都要好。