Androids compose / state documentation contains a sample referring to a mysterious viewModel() function or method, but as the documentation has left out all import statements I can't for the life of me figure out where this function is coming from..

You can check the official doc:
you can access a
ViewModelfrom any composable by calling theviewModel()function.
To use the
viewModel()functions,add theandroidx.lifecycle:lifecycle-viewmodel-compose:$latestVersiondependency to yourbuild.gradlefile.
Finally use:
import androidx.lifecycle.viewmodel.compose.viewModel
Obviously figured it out 2 minutes after giving up and posting the question.
You need this dependency:
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With