hfhbd

    hfhbd

    1 year ago
    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...
    Albert Chang

    Albert Chang

    1 year ago
    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())
    .
    hfhbd

    hfhbd

    1 year ago
    Thanks, makes sense!