Lets say I have a component that render some "static" information and another one that is the parent of these components.
function Foo(){
...
return (
<Bar name="I" {...otherPropsThatChangeFromEachChildren} />
<Bar name="am" {...otherPropsThatChangeFromEachChildren}/>
<Bar name="a" {...otherPropsThatChangeFromEachChildren}/>
<Bar name="children" {...otherPropsThatChangeFromEachChildren}/>
)
}
The Bar
component have props that are static, I will write it in the code, never change and never use in other place.
And here is what confuses me.
Should I have all that static information in an array of objects and render with with .map
e.g.
const staticProperties = [
{
name: "I",
...
},
...
]
function Foo(){
...
return (
staticProperties.map(x =>
<Bar name={x.name} {...x.otherPropsThatChangeFromEachChildren} />
)
)
}
Or just do like the first example
function Foo(){
...
return (
<Bar name="I" {...otherPropsThatChangeFromEachChildren} />
<Bar name="am" {...otherPropsThatChangeFromEachChildren}/>
<Bar name="a" {...otherPropsThatChangeFromEachChildren}/>
<Bar name="children" {...otherPropsThatChangeFromEachChildren}/>
)
}
This is a common thinig that I always think but never know which one is better for maintaining the code and which one is a better to read code.