javascriptandroidreact-nativereact-native-flatlist

Cannot remove child at index 0 from parent viewGroup [370], only 2 children in parent. Warning ChildCount may incorrect


const data = [
  {id: 1, name: 'irfan'},
  {id: 2, name: 'dami'},
];

<FlatList
  data={data}
  renderItem={({item}) => <Text>{item.name}</Text>}
  keyExtractor={(item) => item.id.toString()}
/>

React Native and Dependencies:

react-native: 0.76.6,
react-native-gesture-handler: ^2.22.0,
react-native-screens: ^4.6.0

Error Details:

I get this error when the FlatList is rendered. The warning suggests there is an issue with child removal in the view hierarchy, but I’m not sure how to fix it.

I’ve verified that my keyExtractor is returning a string from the item’s id, and the data array is being passed correctly.

Steps I’ve already tried:

  1. Ensured that keyExtractor returns a string.
  2. Checked for any re-renders or conditional rendering issues with the FlatList.
  3. Tried wrapping the FlatList in a View container to see if it resolves the issue.

Has anyone encountered this issue before?


Solution

  • I was able to work around the same issue by adding removeClippedSubviews={false} to FlatList prop.