rememberStateAndDispatch

@ExperimentalCoroutinesApi
@Composable
fun <S : Any, A : Any> FlowReduxStateMachine<S, A>.rememberStateAndDispatch(): StateAndDispatch<S, A>

Convenient way to get a Compose State to get state update of a FlowReduxStateMachine and a function of type (Action) -> Unit to dispatch Actions to a FlowReduxStateMachine. Under the hood State will be updated only as long as the surrounding Composable is in use. The dispatch function (Action) -> Unit is tight to the same Composable component and launches a coroutine to dispatch actions async. to the FlowReduxStateMachine.

The returned State.value can be null. null means that the FlowReduxStateMachine has not emitted a state yet. That is the case when the coroutine has launched to collect FlowReduxStateMachine.state but since it runs async in a coroutine (a new coroutine is launched under the hood of rememberStateAndDispatch) the FlowReduxStateMachine has not emitted state yet while Jetpack Compose continue its work on the main thread. Therefore, null is used as some sort of initial value and the first value of FlowReduxStateMachine is emitted just a bit later (non null value then).