Search code examples
react-nativefetch-apiflatlist

React native Flatlist rendering from custom API , how to write the code?


I am trying to rendering the value from API, i can see array if i console the values, but not able to see it from Flatlist.

API fetch line is here

see this fetch line

i think this is where i am making mistakes

i think this is where i am making mistakes

console output array

console output array

Help me please,


Solution

  • Data returned from the backend is an array of objects. Refactor renderItem props as below.

    <Flatlist
      keyExtractor={(item) => item.id}
      data={data}
      renderItem={({ item }) => (
        <>
          <Text>{item.date}</Text>
          <Text>{item.date_gmt}</Text>
        </>
      )}
    />