title: Hilt with Jetpack Compose Navigation
body: <p>I checked this info <a href="https://developer.android.com/jetpack/compose/libraries#hilt-navigation" rel="nofollow noreferrer">https://developer.android.com/jetpack/compose/libraries#hilt-navigation</a> how to inject <code>ViewModel</code> to a compose screen.</p>
  <p>For now I implemeted like this for my test app:</p>
  <pre><code>NavHost(
      navController = navController,
      startDestination = startDestination,
      modifier = modifier
  ) {
      composable(Screen.Topics.name) {
          val parentEntry = remember { navController.getBackStackEntry(Screen.Topics.name) }
          val topicsViewModel = hiltViewModel&lt;TopicsViewModel&gt;(parentEntry)
          TopicsScreen(
              topicsViewModel = topicsViewModel,
              openDrawer = openDrawer,
              navigateToTopicDetails = { topic -&gt; actions.navigateToTopicsDetails(topic) }
          )
      }
      ...
  </code></pre>
  <p>Is there will be any difference if I use</p>
  <pre><code>val parentEntry = remember { navController.getBackStackEntry(Screen.Topics.name) }
  val topicsViewModel = hiltViewModel&lt;TopicsViewModel&gt;(parentEntry)
  </code></pre>
  <p>or just</p>
  <pre><code>val topicsViewModel = hiltViewModel&lt;TopicsViewModel&gt;()
  </code></pre>
  <p>I guess first one is needed only if we use nested graphs and we want to get ViewModel for specific graph scope <a href="https://developer.android.com/jetpack/compose/navigation#nested-nav" rel="nofollow noreferrer">https://developer.android.com/jetpack/compose/navigation#nested-nav</a></p>
  <p>So in my case the scope is the same for both methods if I don't use nested graphs?</p>
  <p>So can I just use <code>hiltViewModel&lt;TopicsViewModel&gt;()</code> in my case?</p>