observe

fun <STATE : Any, SIDE_EFFECT : Any> ContainerHost<STATE, SIDE_EFFECT>.observe(lifecycleOwner: LifecycleOwner, lifecycleState: Lifecycle.State = Lifecycle.State.STARTED, state: suspend (state: STATE) -> Unit? = null, sideEffect: suspend (sideEffect: SIDE_EFFECT) -> Unit? = null)

Observe Container.stateFlow and Container.sideEffectFlow correctly on Android in one-line of code. These streams are observed when the view is in Lifecycle.State.STARTED.

In Activities, call from onCreate, where viewModel is a ContainerHost:

viewModel.observe(this, state = ::state, sideEffect = ::sideEffect)

In Fragments, call from onViewCreated, where viewModel is a ContainerHost:

viewModel.observe(viewLifecycleOwner, state = ::state, sideEffect = ::sideEffect)