Is there a recommendation on how to implement filt...
# compose
c
Is there a recommendation on how to implement filtering in a
LazyColumn
?
(code example forthcoming)
Copy code
class SomeItem(val isFavourite: StateFlow<Boolean>)
...

val items: List<SomeItem>
val filterByFavourite by someViewModel.filterByFavourite.collectAsState()

LazyColumn {
  for (item in items) {
    // Can't do this, not in @Composable context
    val isFavourite by item.isFavourite.collectAsState()
    if (filterByFavourite && isFavourite) {
      item {
        // show the item
      }
    }
  }
}
Is there something wrong with doing the below:
Copy code
item {
      val isFavourite by item.isFavourite.collectAsState()
      if (filterByFavourite && isFavourite) {
        // show the item
      }
    }
In the second example, we would end up with empty `item`s being filtered out
Thanks for any advice!
Now that I think of it, better to do the filtering of the collection in the ViewModel
👌 10