Mike Wazowksi
Mike Wazowksi

Reputation: 43

Flatlist can't render items

I wasn't able to understand why it does not render the contents of dummyData when I use it with renderItem arrow function but it works with when I pass {item}) => <Text style={styles.item}>{item.key}</Text> to renderItem props directly

const HomeScreen = ({ navigation }) => {

  const renderItem = ({item}) => {
    <Text style={styles.item}>{item.key}</Text>
  }

  dataUtils.fetchData();
  return(
   <View style={styles.container}>
      <FlatList
        data={dummyData}
        renderItem={renderItem}
        keyExtractor={item => item.id}
      />
    </View>
  );
};

Upvotes: 0

Views: 36

Answers (1)

Felipe Candal Campos
Felipe Candal Campos

Reputation: 173

You are missing a return statement. Delete brackets or add a return.

Like this:

const renderItem = ({item}) =>
    <Text style={styles.item}>{item.key}</Text>

Or:

const renderItem = ({item}) => {
    return <Text style={styles.item}>{item.key}</Text>
}

Upvotes: 2

Related Questions