Jetpack Compose: Pass ViewModel to Composable Function

November 3, 2021
import androidx.lifecycle.viewmodel.compose.viewModel

@Composable
fun ImportPhotoScreen(viewModel: ImportPhotoViewModel = viewModel()) {

}

If the ViewModel has contructor arguments, you probably need Hilt (Dependency Injection)

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.