title: How to use Viewmodel with Jetpack compose
body: <p>I am trying to use <code>ViewModel</code> with Jetpack Compose,</p>
  <p>By doing a number increment.</p>
  <p>But it's not working. Maybe I'm not using the view model in right way.</p>
  <p>Heres my Main Activity code</p>
  <pre><code>class MainActivity : ComponentActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContent {
              Greeting()
          }
      }
  }
  
  @Composable
  fun Greeting(
      helloViewModel: ViewModel = viewModel()
  ) {
      Column(
          verticalArrangement = Arrangement.Center,
          horizontalAlignment = Alignment.CenterHorizontally,
          modifier = Modifier.fillMaxSize()
      ) {
          Text(
              text = helloViewModel.number.toString(),
              fontSize = 60.sp,
              fontWeight = FontWeight.Bold
          )
          Button(onClick = { helloViewModel.addNumber() }) {
              Text(text = &quot;Increment Number ${helloViewModel.number}&quot;)
          }
  
      }
  }
  
  @Preview(showBackground = true)
  @Composable
  fun DefaultPreview() {
      JetpackcomposepracticeTheme {
          Greeting()
      }
  }
  </code></pre>
  <p>And here is my Viewmodel class.</p>
  <p>It works fine with xml.</p>
  <p>How do i create the object of view model:</p>
  <pre><code>class ViewModel: ViewModel() {
      var number : Int = 0
      fun addNumber(){
          number++
      }
  }
  </code></pre>