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) })
}
}
```

View File

@@ -217,7 +217,7 @@ viewModelScope.launch {
```kotlin
@Test
fun `search updates item list`() = runTest {
val fakeRepository = FakeItemRepository(items = testItems)
val fakeRepository = FakeItemRepository().apply { emit(testItems) }
val viewModel = ItemListViewModel(GetItemsUseCase(fakeRepository))
viewModel.state.test {