When dealing with this map() call, how is i getting assigned incremented? What’s it’s default value, and how is it getting that? As I look at this particular call, the only thing that I can see that would make the keys unique is the fact that the ‘person’ name would (hopefully) be.
i is the index of the item, person in this case, in the array map is acting on, people in this case. The initial value of i will be the initial index of an array in JavaScript, 0. The handling of i is done behind the scenes for you. Array.map will pass in a number of things into the function you give it you can find them here:
Hi, so the lesson isn’t explained well at all but I just read in the forums here that the ‘i’ retrieves the index number of the list. So in the key “Person_” is a string and is joined with the index number, so the keys would come out Person_1, Person_2 etc
I still don’t understand why person is wrapped in quotation marks. I understand that the end result (the key) has to be a string but I don’t understand how it evaluates to “Rowe_0”, “Prevost_1” etc. when you don’t pass it the person variable, you are passing it the “person” string.
From this lesson, I am understanding when to use keys. I am not understanding how keys work. Will the keys be sort-ordered based on their own alphanumeric ordering of the key name? Or, is it some more complicated mechanism of how the keys will sort?
Keys allows React to associate each list item with a unique identifier. This makes it efficient for React to decide whether a list item has changed or whether it is the same.
Thank you! In repayment, I report back my findings: I was totally misunderstanding the keys. From the second article, it is more clear to me now.
React is not going to sort the elements by their keys for display; React is just going to match keys. Keys are about knowing which DOM element to update.