3
Problem in rendering my state always gives error:
Warning: Each Child in a list should have a Unique "key" prop.
Check the render method of
Main
. See https://fb.me/react-warning-keys for more information.in li (at main/index.js:42) in Main (at App.js:14) in header (at App.js:12) in div (at App.js:10) in App (at src/index.js:7)
code:
**
render(){
return(
<ol className="planetas-list">
{this.state.Planetz.map(planetas =>(
<li key={planetas.lista}>
{planetas.PlanetzClima}
</li>
))}
</ol>
)
}
}
**
Could you tell me what’s going on? I’ve looked hard at overflow but still couldn’t solve... vlw!
Thanks brother! to breaking my head here but I will delve into the doc of the Act and any questions I put here, if anyone can answer I am grateful!
– Joao Paulo Gardiano
you checked whether the
planetas.lista
is a unique value?– Leo Brescia
I was able to resolve by taking out of my state all {} that were repeating and adding unique id’s to each property that I called in the render. vlw guys!
– Joao Paulo Gardiano
Someone can explain why this Warning is accused when using the function. map() without assigning the key property and not when creating a <View> directly (also without specifying the key)?
– regisls
I didn’t quite understand the question, I’ll try to answer. Key is a special string attribute that you need to define when creating lists of elements. Keys help React identify which items have been changed, added, or removed. Keys must be assigned to the elements within the array to give a stable identity to the elements.
– Leo Brescia