0

Im currently having trouble with rendering an arary of objects into my react native flatlist.

This is my array:

const item = [
{
  "id": 59,
  "id_order": Object {
    "created": "23/08/2021 16:37:55",
    "direccion_extra": "codigo: 0592",
    "id": 39,
    "id_cliente": 35,
    "monto_pago_efectivo": null,
    "status": 1,
    "tipo_pago": 2,
  },
},
{
  "id": 58,
  "id_order": Object {
    "created": "23/08/2021 16:37:55",
    "direccion_extra": "codigo: 0592",
    "id": 39,
    "id_cliente": 35,
    "monto_pago_efectivo": null,
    "status": 1,
    "tipo_pago": 2,
  },
},
]

This is the Flatlist I am trying to render:

<FlatList
    data={item}
    renderItem={({ itemProduct, index }) => <ProductCard item={{itemProduct}} />}}
    keyExtractor={(item, index) => index.toString()}
/>

However, I cannot receive each of the array's objects in the ProductCard component. Any ideas are appreciated!

2 Answers 2

4

there is no itemProduct in renderItem function. It is called item(FYR).

You can rename it by

    renderItem={({ item: itemProduct, index }) 

BTW, the <ProductCard item={{itemProduct}} /> should use one {} only unless you want it to be wrapped in an object.

Sign up to request clarification or add additional context in comments.

Comments

0

Items Array

const items = [
  {
    id: 59,
    id_order: {
      created: '23/08/2021 16:37:55',
      direccion_extra: 'codigo: 0592',
      id: 39,
      id_cliente: 35,
      monto_pago_efectivo: null,
      status: 1,
      tipo_pago: 2,
    },
  },
  {
    id: 58,
    id_order: {
      created: '23/08/2021 16:37:55',
      direccion_extra: 'codigo: 0592',
      id: 39,
      id_cliente: 35,
      monto_pago_efectivo: null,
      status: 1,
      tipo_pago: 2,
    },
  },
];

Flatlist

     <FlatList
        data={items}
        renderItem={({ item }) => ( 
          <View>
            <Text>{item.id}</Text>
          </View>
        )}
        keyExtractor={(item) => item.id}
      />

Note:

In FlatList renderItem you can't write itemProduct you have to write it as item

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.