Thread
#compose
    r

    robnik

    1 year ago
    The docs here show a
    viewModel()
    function, but don't show where to import it. IntelliJ is not helping me. Where is it? (Not sure why I need this magic function. Can I just create my ViewModel like a normal object?)
    i

    Ian Lake

    1 year ago
    The docs specifically around Compose+ViewModel has more information: https://developer.android.com/jetpack/compose/libraries#viewmodel
    The whole point of using a
    ViewModel
    is that it survives configuration changes. As such, it is managed by the system. It is the
    viewModel()
    method that knows whether that ViewModel has already been created (and the retained instance just returned again) or if it needs to be created for the first time