React native flatlist is not showing array of items

Viewed 80

I am going to show an array of items but it is not working, and no error showing up. When I map function with Text component it is working fine. here is my code

import React from 'react';
import {FlatList, StyleSheet, Text, View} from 'react-native';

const AboutScreen = () => {
  const myArray = ['one', 'two', 'three', 'four', 'five', 'six'];
  return (
    <View style={styles.container}>
      <FlatList
        sections={myArray}
        keyExtractor={(item, index) => item + index}
        renderItem={({item}) => <Text style={styles.text}>{item}</Text>}
      />
    </View>
  );
};

export default AboutScreen;

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  text: {
    color: 'red',
  },
});

When I use ListEmptyComponent={<Text>No data found</Text>} its showing "No data found" text on simulator.

1 Answers

Sections is not a prop of FlatList but of SectionList. Simply change sections={myArray} to data={myArray} and it should work.

Related