react-native: FlatList is not rendering the complete list of items.

Description

It seems that there is a bug on the react-native flatlist while trying to render a list of items. Sometimes only some of the list items are displayed. When there are interactions such as state changes, there is an update in the list and all the list items are displayed properly.

React Native Version

0.72.4

Output of npx react-native info

System: Binaries: Node: version: 16.20.0 Yarn: version: 1.22.19 npm: version: 8.19.4

SDKs: iOS SDK: Platforms: - DriverKit 22.2 - iOS 16.2 - macOS 13.1 - tvOS 16.1 - watchOS 9.1 Android SDK: API Levels: - “23” - “28” - “29” - “30” - “31” - “32” - “33” - “34” Build Tools: - 29.0.2 - 30.0.2 - 30.0.3 - 31.0.0 - 33.0.0 - 34.0.0

Languages: Java: version: 11.0.15 Ruby: version: 2.6.10 react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.4 wanted: 0.72.4 Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: true newArchEnabled: false

Steps to reproduce

We are using a FlatList to render a List of 500-1000 items based on a dynamic response. We are updating the states based on navigations and data filter. However sometimes in the initial load of the page the Flatlist is rendering only 5 items and it is unable to render the remaining items when scrolling down.

When there are state changes after initial load of data, there is an update in the list and all the data items are displayed properly.

Snack, screenshot, or link to a repository

Attaching an example link only for depicting the flatlist configuration we use. https://stackoverflow.com/questions/77036267/issue-flatlist-rendering-only-few-items-in-the-list

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 1
  • Comments: 23 (1 by maintainers)

Most upvoted comments

I’m also facing the same issue after upgrading to React Native to 0.72.4. FlatList is only rendering the number of items defined in ‘initialNumToRender’. Rest of the items are not getting rendered, so I’m not able to scroll over those items.

I’m also facing the same problem. I upgraded my react native from 0.63…3 to 0.72.4 and suddenly my Flatlist stopped rendering views. Before upgrade It was working absolutely fine.

<FlatList horizontal data={reviewQuestionArray} disableIntervalMomentum={true} ref={ref => (this.flatListRef = ref)} // onViewableItemsChanged={this.onViewableItemsChanged } viewabilityConfig={{ itemVisiblePercentThreshold: 50, }} onMomentumScrollEnd={this.onScrollEnd} onEndReached={this.loadMoreData} //disableVirtualization = {true} initialNumToRender={1} pagingEnabled keyExtractor={keyExtractor} getItemLayout={getItemLayout} maxToRenderPerBatch={10} windowSize={3} snapToInterval={WINDOW_WIDTH} renderItem={({ item, index }) => } />

My flatlist worked finally. You have to put an empty check before you render flatlist “reviewQuestionArray.length >0”.

(reviewQuestionArray.length>0) &&
<FlatList horizontal data={reviewQuestionArray} disableIntervalMomentum={true} ref={ref => (this.flatListRef = ref)} // onViewableItemsChanged={this.onViewableItemsChanged } viewabilityConfig={{ itemVisiblePercentThreshold: 50, }} onMomentumScrollEnd={this.onScrollEnd} onEndReached={this.loadMoreData} //disableVirtualization = {true} initialNumToRender={1} pagingEnabled keyExtractor={keyExtractor} getItemLayout={getItemLayout} maxToRenderPerBatch={10} windowSize={3} snapToInterval={WINDOW_WIDTH} renderItem={({ item, index }) =>

} />

Based on the answers above, I created a custom component to fix the issue:

import React, { useCallback } from 'react';
import { FlatList, ScrollView, FlatListProps } from 'react-native';

interface Props extends FlatListProps<any> {}

export default React.memo<Props>((props: Props) => {
    const { ListEmptyComponent, ...rest } = props;

    const renderComponent = useCallback((component: any) => {
        return component ? (component instanceof Function ? component() : component) : null;
    }, []);

    return rest.data && rest.data.length === 0 ? (
        <ScrollView {...rest}>
            {renderComponent(rest.ListHeaderComponent)}
            {renderComponent(ListEmptyComponent)}
            {renderComponent(rest.ListFooterComponent)}
        </ScrollView>
    ) : (
        <FlatList {...rest} />
    );
});

I am facing the same issue after upgrading to version 0.72.4. The FlatList component is not rendering all the items. By default, it only renders around 10 items. If I specify a number in the ‘initialNumToRender’ prop, then only that number of items is displayed.

I’m also facing the same problem. I upgraded my react native from 0.63…3 to 0.72.4 and suddenly my Flatlist stopped rendering views. Before upgrade It was working absolutely fine.

<FlatList horizontal data={reviewQuestionArray} disableIntervalMomentum={true} ref={ref => (this.flatListRef = ref)} // onViewableItemsChanged={this.onViewableItemsChanged } viewabilityConfig={{ itemVisiblePercentThreshold: 50, }} onMomentumScrollEnd={this.onScrollEnd} onEndReached={this.loadMoreData} //disableVirtualization = {true} initialNumToRender={1} pagingEnabled keyExtractor={keyExtractor} getItemLayout={getItemLayout} maxToRenderPerBatch={10} windowSize={3} snapToInterval={WINDOW_WIDTH} renderItem={({ item, index }) => <QuestionCard item={item} index={index} /> }
/>