a state on each item of a hoisted list.
The idea is that an item’s state is remembered even if the list has been updated.
Is it possible right now?
Copy code
@Composable
fun Component(list: List<T>) {
list.forEach { item ->
// something like this but this won't work
// this should stay as false if (someCondition) for the unchanged iteems even if the list is updated
val rememberedFlag = remember(item) { mutableStateOf(true) }
if (someCondition) rememberedFlag.value = false
}
}
Edit: ^Actually works apparently
z
Zach Klippenstein (he/him) [MOD]
11/17/2020, 4:54 AM
If your list items implement hashcode/equals, you probably just need to wrap everything inside your
forEach
with
key(item) { … }
.
a
allan.conda
11/17/2020, 4:57 AM
wait… my code actually works, huh. somehow I assumed it wouldn’t