Answers for "When rendering a list what is a key and what is it's purpose?"

1

react component key prop

function ListItem(props) {
  // Correct! There is no need to specify the key here:  return <li>{props.value}</li>;}

function NumberList(props) {
  const numbers = props.numbers;
  const listItems = numbers.map((number) =>
    // Correct! Key should be specified inside the array.    <ListItem key={number.toString()} value={number} />  );
  return (
    <ul>
      {listItems}
    </ul>
  );
}

const numbers = [1, 2, 3, 4, 5];
ReactDOM.render(
  <NumberList numbers={numbers} />,
  document.getElementById('root')
);
Posted by: Guest on September-14-2020
0

When rendering a list what is a key and what is it's purpose?

ReactDOM.render(
  <ul>{listItems}</ul>,  document.getElementById('root')
);
Posted by: Guest on February-06-2021

Code answers related to "When rendering a list what is a key and what is it's purpose?"

Browse Popular Code Answers by Language