Thuta Learning
BasicWeb Developmentintermediate

Lists & Keys

Relax. We'll talk through this in plain words — no textbook voice.

In React, you use JavaScript's `map()` to turn array data into a UI list. Repeated UI like blog posts, products, menu items, notifications, and lessons can all be built with list rendering.

jsx
function TodoList() {
  const todos = [
    { id: 1, text: 'Learn React' },
    { id: 2, text: 'Build a project' },
    { id: 3, text: 'Deploy the project' }
  ];

  return (
    <ul>
      {todos.map(todo => (
        <li key={todo.id}>{todo.text}</li>
      ))}
    </ul>
  );
}

`todos.map()` turns each item in the array into an `

` element. `key={todo.id}` lets React tell each item apart from the others.

You should see
A bullet list with three lines will appear — Learn React, Build a project, Deploy the project.

Info

When you add, remove, or reorder items in a list, getting the key right makes UI updates predictable and cuts down on bugs.

Easy traps

  • If you leave out `key`, you'll get a console warning, and the UI can become unstable during certain list updates.