Jasur Kurbanov
Jasur Kurbanov

Reputation: 830

FlatList is not showing anything in React Native

I do have such kind of JSON. I am getting it on my React Native app.

order:[
    {
    "id": "00005497",
    "order_number": "525522",
    "order_result_json": [
      {
        "key": "Номер",
        "value": "25263640253590"
      },
      {
        "key": "Ссылка на скачивание",
        "value": "https://play.google.com/store/"
      },
      {
        "key": "Ссылка на лицензию",
        "value": "https://google.com"
      }
    ]
}]

I can see that data is coming: alert(JSON.stringify(order.orderResultJson)); this is showing that array is coming.

When I am applying it to my FlatList, it is showing empty space, and if I scrolling page down it is going infinite scroll with empty content.

My FlatList implementation:

<View style={{flex: 1, backgroundColor: 'green'}}>
     <FlatList
           data={order.orderResult}
           renderItem={({item}) => <Text>{item.value}+5</Text>} 
           keyExtractor={item => item.key} 
      />   
</View>

Any suggestions?

Upvotes: 1

Views: 135

Answers (2)

sanjar
sanjar

Reputation: 1101

order is an array, so you cannot access order.orderResult.

2 solutions :

  • Use the first item of the order array : order[0].orderResult
  • Change the structure of the order object (why is it an array?)

Upvotes: 0

Pierre V.
Pierre V.

Reputation: 1625

Isn't just a typo?

Your code uses data={order.orderResult}, but your json data contains order_result_json, and your debugging code with alert uses orderResultJson

Upvotes: 2

Related Questions