Arrays and key value pairs (Map / Object) in React

I am often torn by the weather or not. I have to use the data structure of a pair of values ​​or an array in React when presenting a collection of uniquely identifiable objects.

For example, if we want a component to receive a collection of messages, is there something wrong with their modeling,

{
 message1: {from:"bill" , to:"frank"} , 
 message2: {from:"Jill" , to:"sammy"}
}

or similar to the ES6 card, or we should use an array of objects like this

[
{name:"message1" , from:"bill" , to:"frank"} , 
{name:"message2" , from:"Jill" , to:"sammy"}
]

I would like to know if there is any good practice for using key value data structures in React.

+4
source share

Source: https://habr.com/ru/post/1673655/


All Articles