diff --git a/topics/compose/compose-viewmodel.md b/topics/compose/compose-viewmodel.md index 2657d4b1..d667c0f5 100644 --- a/topics/compose/compose-viewmodel.md +++ b/topics/compose/compose-viewmodel.md @@ -34,25 +34,27 @@ Using the [navigation example](https://github.com/JetBrains/compose-multiplatfor 1. Declare the ViewModel class: - ```kotlin - class OrderViewModel : ViewModel() { - private val _uiState = MutableStateFlow(OrderUiState(pickupOptions = pickupOptions())) - val uiState: StateFlow = _uiState.asStateFlow() - - // ... - } - ``` +```kotlin +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewmodel.compose.viewModel + +class OrderViewModel : ViewModel() { + private val _uiState = MutableStateFlow(OrderUiState(pickupOptions = pickupOptions())) + val uiState: StateFlow = _uiState.asStateFlow() + // ... +} +``` 2. Add the ViewModel to your composable function: - ```kotlin - @Composable - fun CupcakeApp( - viewModel: OrderViewModel = viewModel { OrderViewModel() }, - ) { - // ... - } - ``` +```kotlin +@Composable +fun CupcakeApp( + viewModel: OrderViewModel = viewModel { OrderViewModel() }, +) { + // ... +} +``` > When running coroutines in a `ViewModel`, remember that the `ViewModel.viewModelScope` value is tied to the `Dispatchers.Main.immediate` value, > which might be unavailable on desktop by default. diff --git a/v.list b/v.list index 3fcb7d39..22f9b7c3 100644 --- a/v.list +++ b/v.list @@ -26,8 +26,8 @@ - + - +