https://kotlinlang.org logo
#android
Title
# android
a

Adam V

09/08/2023, 4:15 PM
I've got a curious condition in regards to recomposition in Jetpack Compose for lazy lists. I assume that it's some kind of magic that Compose uses to determine what is and is not in scope, but it's still a bit confusing. I'm particular, it seems that, where
state
is a
MutableState
containing a list, and the list is being consumed in a Lazy container of some kind
Copy code
var x = state.value
items(x, ...) {
...
Does Not cause recomposition on every element in the list, while
Copy code
items(state.value, ...) {
...
Does force all items to recompose. In theory, moving
state.value
into its own local variable that is immediately referenced should not cause any difference, but it clearly appears to be the case here. What am I missing here? I understand that this is more of a Compose question than a Kotlin question, but it feels language appropriate.
jetpack compose 2