I don't know how to consume `Flow` properly in Com...
# compose-desktop
f
I don't know how to consume
Flow
properly in Compose Desktop, I have searched but only find examples for Android. I get the data from Kmongo:
Copy code
class TagDAO {
    companion object {
        private val tagsDB by lazy { Connection().getCollection<Tag>("tags") }
        fun listTags(): Flow<Tag> {
            return tagsDB.find().toFlow()
        }
    }
}

@Composable
fun form() {
  val tagsFlow = TagDAO.listTags() // Flow<Tag>
  val tagsState by tagsFlow.collectAsState(initial = Tag()) // Only return last value
}
h
First: use remember to remember the flow avoiding to query the db each recomposition
by remember { tagDao.listTags() }.collectAsState()}
. And what do you mean with
last
value? A flow returns values over time. Compose updates your UI over time. So yeah, you always see the last value of the flow. If you want to show a list, you should fetch a list:
Flow<List<Tag>>
f
Sry, I forgotten
remember
to paste code. Yes, I want obtain list of values.
Kmongo
returns
List<Tag>
or
Flow<Tag>
, not like ROOM of Android that returns
Flow<List<Tag>>
.