sideEffects

Creates a Middleware that handles side effects. A side effect observes specified actions and may dispatch other actions. This can handle asynchronous operations using coroutines.

An example that fetches data from an API when the Action.Request action is dispatched:

val sideEffectsMiddleware = sideEffects<State, Action> {
collect<Action.Request> { action ->
val data = api.fetchData()
dispatch(Action.Result(data))
}
}