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
hfhbd
11/29/2022, 11:37 AM
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: