I'm following the ReactJS tutorial from www.tutorialpoints.com and I'm at this page
In a nutshell it provides the following data in JSON format:
this.state = {
data:
[
{
"id":1,
"name":"Foo",
"age":"20"
},
{
"id":2,
"name":"Bar",
"age":"30"
},
{
"id":3,
"name":"Baz",
"age":"40"
}
]
}
and is looping through it with the map function below:
{this.state.data.map((person, i) => <TableRow key = {i} data = {person} />)}
What I fail to understand is why are they using a tuple (person, i) to target EACH object and how is the key = {i} part of the code working. I have tried removing the key part and the code still works. From further reading I understood that it helps reload only the specific data that has been changed instead of the whole dataset, but I'm not sure.
Can anyone go through ONLY the loop in that example line by line to clarify how this works?