在状态更改时不呈现React Native Flatlist ListHeaderComponent

时间:2020-06-15 10:03:57

标签: react-native react-native-flatlist

我有带有ListHeaderComponent的Flatlist。状态更新时,ListHeaderComponent不更新。任何建议都会有所帮助。

                    <Animated.FlatList data={this.props.store.homeStore.formattedEspeciallyProducts}
                        contentContainerStyle={styles.flatList}
                        ref={(ref) => this.flatList = ref}
                        onScroll={
                            Animated.event(
                                [{nativeEvent: {contentOffset: {y: this.scrollY}}}], 
                                {
                                    useNativeDriver: true
                                }
                            )
                        }
                        renderItem={({ item, index }) => {
                            return(
                                <SpecialProduct product={item} even={(index + 1) % 2 === 0}/>
                            )
                        }}    
                        showsVerticalScrollIndicator={false}
                        keyExtractor={item => item.id}
                        numColumns={2}
                        onEndReached={this._onEndReached}
                        onEndReachedThreshold={0.5}
                        ItemSeparatorComponent={this._itemSeparatorComponent}
                        removeClippedSubviews={true}
                        columnWrapperStyle={{paddingHorizontal: 15}}
                        extraData={language}
                        ListHeaderComponent={
                            <View style={CssHelper['flex']}>
                                <View style={styles.top}>

1 个答案:

答案 0 :(得分:0)

由于Flatlist是PureComponent,因此不会在状态更改时重新呈现。将您的状态传递到data属性以实现状态感知https://reactnative.dev/docs/flatlist#data