简体   繁体   English

React Native Flatlist ListHeaderComponent 未在 state 更改上呈现

[英]React Native Flatlist ListHeaderComponent is not rendered on state change

I have Flatlist with ListHeaderComponent.我有带有 ListHeaderComponent 的 Flatlist。 When state is updated ListHeaderComponent is not updating.当 state 更新时,ListHeaderComponent 不会更新。 Any suggestion would be helpful.任何建议都会有所帮助。

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

Since Flatlist is a PureComponent it will not rerender on state changes.由于 Flatlist 是一个PureComponent ,它不会在 state 更改时重新呈现。 Pass your state to the data property to achieve state awareness https://reactnative.dev/docs/flatlist#data将您的 state 传递给data属性以实现 state 感知https://reactnative.dev/docs/flatlist#data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Algolia和React Native FlatList ListHeaderComponent - Algolia and React Native FlatList ListHeaderComponent React Native Flatlist ListHeaderComponent 不起作用 - React Native Flatlist ListHeaderComponent Doesn't Work 如何使 ListHeaderComponent 的一部分粘在 React Native FlatList 上 - How to make a part of ListHeaderComponent sticky on React Native FlatList 如何在 React Native 平面列表中滚动期间隐藏 ListHeaderComponent - How do I hide the ListHeaderComponent during scroll in a React Native flatlist 你如何让 React Native FlatList 的 ListHeaderComponent 变得有粘性? - How do you make the ListHeaderComponent of a React Native FlatList sticky? 渲染后如何在不刷新 React Native 上的其他项目的情况下更改 FlatList 项目的 state - How to change state of FlatList item after rendered without refreshing other item on React Native 为什么React Native FlatList样式不会随状态而改变 - Why React Native FlatList style not change with state React Native:Flatlist 渲染组件 state 渲染了错误的数据? - React Native: Flatlist rendered component state renders wrong data? React Native Android 关注 Flatlist 的粘性 ListHeaderComponent 中的 TextInput 使列表滚动 position 对齐到 y = 0 - React Native Android focus on TextInput inside Flatlist's sticky ListHeaderComponent makes list scroll position snap to y = 0 React Native - FlatList - 内部状态 - React Native - FlatList - Internal State
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM