Skip to content
Learn Netverks

Lesson

Step 10/36 28% through track

lists-keys

Lists and keys

Last reviewed May 28, 2026 Content v20260528
Track mode
client_react
Means
In-browser React TSX
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Lists and keys: the concepts, APIs, and habits you need before advancing in React.

Lists without stable keys break focus, animation, and state in production tables and feeds.

You will apply Lists and keys in contexts like: Product grids, notification feeds, and searchable result lists.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

Render arrays with .map(). Each sibling in a list needs a stable key so React can match items across renders when order changes.

Keys

  • Use stable IDs from data (user.id), not array index—unless the list is static and never reordered.
  • Keys are hints for reconciliation—they do not appear in the DOM.
  • Do not generate random keys on every render.
{items.map((item) => (
  <li key={item.id}>{item.label}</li>
))}

Important interview questions and answers

  1. Q: Why not use index as key?
    A: Reordering, inserting, or deleting items can cause wrong component state to stick to the wrong row.
  2. Q: Where do keys go?
    A: On the outermost element returned from the map callback—not on the fragment unless it has a key prop.

Self-check

  1. What happens if you omit keys in development?
  2. When is index-as-key acceptable?

Pitfall: Using array index as key breaks when items reorder, insert, or delete—use stable ids from your data.

Interview prep

Why do keys matter in lists?

Keys identify items across renders—use stable ids, not random values or index when order can change. Wrong keys lose focus and state.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Bad key example?
  • Stable id source?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump