Why is my FlatList not showing?

dbarks picture dbarks · Jul 16, 2018 · Viewed 8.8k times · Source

I am trying to load this FlatList but it is not showing anything in the screen and I am not getting errors. The breed console.log is logging an array of objects with keys of $t.

The console log of this.props.breeds.breed is below.

(37) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0
:
{$t: "Affenpinscher"}
1
:
{$t: "Afghan Hound"}
2
:
{$t: "Airedale Terrier"}
...

Answer

JDune picture JDune · Jul 16, 2020

This also happens if you forget to return something from your renderItem function. For example:

renderItem = (row, sectID, rowID) => {
   <View style={{flexDirection: 'row'}}>
     <Text>{row.item}</Text>
   </View>;
};

As you can see the return statement is missing, but this doesn't trigger an error, warning or anything - you just get a blank Flatlist.