A
A
aris-paskalov2022-01-10 10:54:17
React
aris-paskalov, 2022-01-10 10:54:17

Where in this case to take the keys for the elements?

Good day.
I'm writing a React Native weather app.

I'm making an API request, and then I'm rendering weather components using the .map() method.

But I don't know where to get the key for the key property.
Response items don't have a key

Please tell me how to set the keys in this case?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2022-01-10
@aris-paskalov

In this case, just take it in order:

data.map((elem, i) => <Component data={elem} key={i}/>)

K
Kirill Makarov, 2022-01-17
@kirbi1996

You can use the element index if you don't mean deleting the array elements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question