docs: tighten kotlin support examples

This commit is contained in:
Affaan Mustafa
2026-03-10 20:50:34 -07:00
committed by Affaan Mustafa
parent f6a470de63
commit 7433610105
7 changed files with 28 additions and 8 deletions

View File

@@ -252,11 +252,12 @@ val showScrollToTop by remember {
// BAD — new lambda and list every recomposition
items.filter { it.isActive }.forEach { ActiveItem(it, onClick = { handle(it) }) }
// GOOD — remember filtered list, stable lambda with key
// GOOD — key each item so callbacks stay attached to the right row
val activeItems = remember(items) { items.filter { it.isActive } }
activeItems.forEach { item ->
val onClick = remember(item.id) { { handle(item) } }
ActiveItem(item, onClick = onClick)
key(item.id) {
ActiveItem(item, onClick = { handle(item) })
}
}
```