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

hfhbd

08/30/2021, 6:57 PM
What is the reason to not update the UI if you use Room directly with Compose:
dao.get().collectAsState(emptyList())
with
interface Dao { @Query(...) fun get(): Flow }
? You have to use a ViewModel to get updates on DB changes. WA: wrap the
collect
in VM and emit them to the flow accessed by Compose...
a

Albert Chang

08/31/2021, 12:05 AM
dao.get()
is a function, which means every time it is called you get a new flow, and it will be called on every recomposition. If you really want to use it directly in a composable function, you should use
remember { dao.get() }.collectAsState(emptyList())
.
h

hfhbd

08/31/2021, 7:38 AM
Thanks, makes sense!