我有带有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}>
答案 0 :(得分:0)
由于Flatlist是PureComponent
,因此不会在状态更改时重新呈现。将您的状态传递到data
属性以实现状态感知https://reactnative.dev/docs/flatlist#data