> You can use `rememberViewModelStoreOwner()` t...
# compose
m
You can use
rememberViewModelStoreOwner()
to scope a ViewModel directly to the call site of a composable. […] When the composable that owns the`ViewModelStoreOwner` leaves the composition, the associated
ViewModelStore
is cleared and the
ViewModel
is destroyed.
Doesn’t this contradict
Use
rememberViewModelStoreOwner()
to create a lifecycle-aware store that survives configuration changes.
Because compositions are dropped on configuration change, which means the
ViewModel
would be destroyed?
Additionally, what would be the difference between the featured example:
Copy code
@Composable
fun RememberViewModelStoreOwnerSample() {
    val scopedOwner = rememberViewModelStoreOwner()

    CompositionLocalProvider(LocalViewModelStoreOwner provides scopedOwner) {
        val viewModel = viewModel { TestViewModel("scoped_data") }
    }
}
And doing the following:
Copy code
@Composable
fun RememberViewModelStoreOwnerSample() {
    val viewModel = viewModel(
        viewModelStoreOwner = rememberViewModelStoreOwner()
    ) {
        TestViewModel("scoped_data")
    }
}