```LazyColumn(modifier = modifier) { for (name...
# compose
a
Copy code
LazyColumn(modifier = modifier) {
    for (name in names) {
        Greeting(name = name)
        Divider(color = Color.Black)
    }
}
p
you're doing it wrong
you shouldn't use for loop
a
yeah the official doc actually does this:
Copy code
LazyColumn(modifier = modifier) {
       items(items = names) { name ->
           Greeting(name = name)
           Divider(color = Color.Black)
       }
   }
p
yeah, they're using "items"
a
I am not familiar with this paradigmm
p
no worries
a
I thought what works for Column must work for LazyColumn
i’m trying to understand what’s different
@Peter Mandeljc i think it uses items to recompose on scroll but the error seems misleading i think
p
items() is a method, that takes a "builder" that builds your item (row) on demand
a
aha
@Peter Mandeljc
Copy code
items(items = names) { name ->
           Greeting(name = name)
           Divider(color = Color.Black)
       }
is not working
says items is not a valid parameter
Solved it. Wrong import. Thanks for the help
🍻 1
c
The difference between Column and LazyColumn is that the second one only computes items that are visible on screen. If you use
for (name in names)
, you are going through all the
names
(standard Kotlin syntax), which means you are trying to display all of the names. That's fine for Column, but LazyColumn doesn't want all names, it just wants the ones visible on screen. By using the
items
function (specific to Compose), you are telling LazyColumn how to compute a single item, and Compose will then use that multiple times on just the items that are on screen.
👍 1
a
@CLOVIS that’s how i understood it. I just didn’t feel that the error message is right
it make it look like a syntax error for me
c
Well, it is an error. It doesn't make sense to force-feed items to a LazyColumn, the LazyColumn decides what is shown, not you.
a
ok thanks for the explanation @CLOVIS