
The coroutine will beĬancelled if LaunchedEffect leaves the composition.
SIDE EFFECT CODE
When LaunchedEffect enters the Composition, it launches aĬoroutine with the block of code passed as a parameter. To call suspend functions safely from inside a composable, use theĬomposable. LaunchedEffect: run suspend functions in the scope of a composable Learn more about Coroutines, check out the Kotlin coroutines onĪndroid guide. This by embracing coroutines at the API level instead of using callbacks. Note: A responsive UI is inherently asynchronous, and Jetpack Compose solves Make sure that the work you do in them is UI related andĭoesn't break unidirectional data flow as explained in the Managing stateĭocumentation. Side effects to run when a composition completes.ĭue to the different possibilities effects open up in Compose, they can beĮasily overused. Key Term: An effect is a composable function that doesn't emit UI and causes State documentation doc), you should use the EffectĪPIs so that those side effects are executed in a predictable manner. When you need to makeĬhanges to the state of the app (as described in the Managing State and effect use casesĭocumentation, composables should be side-effect free.

You'll learn about the different side-effect APIs Jetpack Compose offers.

These actions should be called from a controlledĮnvironment that is aware of the lifecycle of the composable. However, sometimes side-effects are necessary, for example, to trigger a one-offĮvent such as showing a snackbar or navigate to another screen given a certain Recompositions that can be discarded, composables should ideally be side-effect Recompositions, executing recompositions of composables in different orders, or

A side-effect is a change to the state of the app that happens outside theĭue to composables' lifecycle and properties such as unpredictable
