https://kotlinlang.org logo
#compose
Title
# compose
s

Se7eN

02/01/2021, 11:30 AM
I'm getting a crash when doing this:
Copy code
val items = viewModel.items.collectAsState(initial = listOf())
LazyColumn {
    items(items.value.size) { index ->
        ...
    }
}
But if I do
val items = viewModel.items.collectAsState(..).value
and
items(items.size)
, it works fine. Why doesn't the first snippet work?
s

Se7eN

02/01/2021, 12:04 PM
My question is about the state
c

Cyril Find

02/01/2021, 12:07 PM
oh ok sorry for the quick response what i meant is the methods were moved around so it’s maybe not using the one you expected
k

Kshitij Patil

02/01/2021, 3:18 PM
Why you're passing
items.size
to
items() when
you can use
itemsIndexed()
👍 1
2 Views