How to scope a ViewModel to a screen in navgraph w...
# compose
k
How to scope a ViewModel to a screen in navgraph when using hilt and navigation component?
Alright got it, they changed the way it was done
Copy code
// import androidx.hilt.navigation.compose.hiltViewModel
// import androidx.navigation.compose.getBackStackEntry

@Composable
fun MyApp() {
    NavHost(navController, startDestination = startRoute) {
        navigation(startDestination = innerStartRoute, route = "Parent") {
            // ...
            composable("exampleWithRoute") { backStackEntry ->
                val parentViewModel = hiltViewModel<ParentViewModel>(
                    navController.getBackStackEntry("Parent")
                )
                ExampleWithRouteScreen(parentViewModel)
            }
        }
    }
}
c
I just saw something called Maverick today that sounded like it does this: https://gpeal.medium.com/mavericks-meet-jetpack-compose-cf6721f2ea88