List Rendering

List rendering is displaying an array of data as repeated elements in React, typically by calling .map() to turn each item into a piece of JSX. Each rendered item should get a unique key prop.

React

To show a list, you transform a JavaScript array into an array of JSX elements with .map(), and React renders them in order. This is how you display things like a list of products, comments, or to-do items.

React needs a stable, unique key on each item so it can track which elements changed between renders. Use a stable id from your data for the key whenever possible, and avoid using the array index when the list can be reordered or filtered.

Examples

JSX — Renders an unordered list with three list items: apple, banana, and cherry.

function FruitList() {
  const fruits = ["apple", "banana", "cherry"];
  return (
    <ul>
      {fruits.map((fruit) => (
        <li key={fruit}>{fruit}</li>
      ))}
    </ul>
  );
}

Learn it in a lesson

See also

Back to the Dictionary