Hi, There was some suggestion to use `collectAsSta...
# compose
s
Hi, There was some suggestion to use
collectAsStateWithLifecycle
on consumer side and
stateIn
in producer side to restrict view getting updates https://medium.com/androiddevelopers/consuming-flows-safely-in-jetpack-compose-cde014d0d5a3 https://medium.com/androiddevelopers/things-to-know-about-flows-sharein-and-statein-operators-20e6ccb2bc74
Copy code
.stateIn(
            viewModelScope,
            SharingStarted.WhileSubscribed(5000L),
            null
        )
Also there was some suggestion to use it to fetch initial data for a screen rather than using
init
or
LaunchedEffect(Unit)
as it have its own issue. One problem which I found was the data will be re-fetched if screen is kept in background for more than 5s which is kind of making bad UX if we don't hold data in repo layer. Are there any better approach for fetching initial data from compose screens ?
d
If initial data that you are fetching is independent of any navigation ARGS ...always better to go with viewmodel init I think