0Pricing
Jetpack Compose Academy · Lesson

Keys for Stable, Fast Lists

Help Compose track items across changes.

Keys for Stable, Fast Lists is a free Jetpack Compose Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

How Compose Tracks Rows

By default, Compose identifies each row by its position in the list. Item zero is item zero, item one is item one, and so on.

Position Breaks on Change

When you insert or remove a row, every item below shifts position. Compose now thinks those rows are different and rebuilds them needlessly.

The Cost of Confusion

Rebuilt rows lose their state and animations. A removed item can make the whole list flicker as Compose reshuffles everything below it.

Give Each Item a Key

A key is a stable, unique value that names each item by identity, not position. Then Compose follows items even as they move.

items(users, key = { it.id }) { user ->
    Text(user.name)
}

Use a Real Unique ID

The best key is a true unique id from your data, like a database id. It stays the same no matter where the item sits.

Keys Must Be Unique

Every key in the list must be different. Duplicate keys throw a runtime error, so never key items by a value two rows might share.

Don't Key by Index

Using the index as a key defeats the purpose, since indexes shift just like position. Reach for it only when you truly have no id.

State Stays With the Item

With stable keys, a row's remembered state travels with it. A checkbox stays checked even after items above it are deleted.

Keys Power Animations

Stable keys let Compose animate items moving, appearing, or leaving. Without them, it can't tell a move from a rebuild.

items(items, key = { it.id }) { item ->
    Text(item.label, Modifier.animateItem())
}

itemsIndexed Takes Keys Too

The itemsIndexed builder also accepts a key lambda. You still get the index, plus stable identity for every row.

itemsIndexed(data, key = { _, item -> item.id }) { i, item ->
    Text("$i: ${item.name}")
}

Keys Are Almost Always Worth It

For any list that can change, adding keys is a tiny effort with a big payoff: correct state, smooth animations, and fewer rebuilds.

Quick Check

What makes a good list key?

Recap: Stable Keys, Stable Lists

Keys give items identity beyond position. Use a real unique id, keep keys unique, and your state and animations just work. ✨

Frequently asked questions

Is the “Keys for Stable, Fast Lists” lesson free?

Yes — the full text of “Keys for Stable, Fast Lists” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.

What will I learn in “Keys for Stable, Fast Lists”?

Help Compose track items across changes. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Jetpack Compose Academy?

No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Keys for Stable, Fast Lists” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Jetpack Compose Academy lesson?

Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. LazyColumn vs Scrollable Column
  2. items & itemsIndexed
  3. Keys for Stable, Fast Lists
  4. Sticky Headers & Section Lists
← Back to Jetpack Compose Academy