In fragment, we have
private val activityViewModel: MainActivityViewModel by activityViewModels()
private val fragmentViewModel: MainFragmentViewModel by viewModels()
to get an instance of a shared view model throughout the app (activity view model) and a view specific view model (fragment view model).
I am migrating to compose.
How to get two view models with different scopes in jetpack compose?
From the docs, I can see this line,
viewModel() returns an existing ViewModel or creates a new one in the given scope.
But, how do I specify the scope of the view model?
P.S.
I have already gone through this question which is similar but it doesn't have any answers.
onCreate
and pass it to each route. What's the difference? – Humanly