Tgo1014

    Tgo1014

    1 year ago
    What’s the best way to scope a VM inside a composable? I’ve a Pager with x screen and they all use the same VM, but I need a different instance for each screen. Any ideas?
    Albert Chang

    Albert Chang

    1 year ago
    CompositionLocalProvider(LocalViewModelStoreOwner provides yourViewModelStoreOwner) { ... }
    Also here is the feature request.
    Tgo1014

    Tgo1014

    1 year ago
    Yeah, that’s what I’m doing right now but for this to work I need to inject everything in the Activity and pass as parameters to all screens down to the one I need because I’ve to create the vm using the factory instead of using
    hiltViewModel()
    . So I was wondering if there was already some better way to do it Thanks!