Answer the question
In order to leave comments, you need to log in
Reactjs Lists and Keys documentation question?
https://codepen.io/gaearon/pen/jrXYRR?editors=0011
https://reactjs.org/docs/lists-and-keys.html
This is the part
<li key={number.toString()}>
{number}
</li>
Answer the question
In order to leave comments, you need to log in
You may not have noticed, but the array in the examples is called numbers , and the callback argument to which the array element is passed is number .
Initial data:
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
<li key={number.toString()}>
{number}
</li>
);
[
<li key="1">1</li>,
<li key="2">2</li>,
<li key="3">3</li>,
<li key="4">4</li>,
<li key="5">5</li>,
]
<ul>
{listItems}
</ul>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question