---
title: "LaunchedEffect"
description: "When [LaunchedEffect] enters the composition it will launch [block] into the composition's
[CoroutineContext]. The coroutine will be [cancelled][Job.cancel] when the [LaunchedEffect]
leaves the composition.

It is an error to call [LaunchedEffect] without at least one `key` parameter."
type: "composable"
---

<div class='type'>Composable Function</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


> **Deprecated** LaunchedEffectNoParamError

```kotlin
@Composable
public fun LaunchedEffect(block: suspend CoroutineScope.() -> Unit): Unit
```


When `LaunchedEffect` enters the composition it will launch `block` into the composition's
`CoroutineContext`. The coroutine will be `cancelled` when the `LaunchedEffect`
leaves the composition.

It is an error to call `LaunchedEffect` without at least one `key` parameter.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public fun LaunchedEffect(key1: Any?, block: suspend CoroutineScope.() -> Unit)
```


When `LaunchedEffect` enters the composition it will launch `block` into the composition's
`CoroutineContext`. The coroutine will be `cancelled` and **re-launched** when
`LaunchedEffect` is recomposed with a different `key1`. The coroutine will be
`cancelled` when the `LaunchedEffect` leaves the composition.

This function should **not** be used to (re-)launch ongoing tasks in response to callback events
by way of storing callback data in `MutableState` passed to `key1`. Instead, see
`rememberCoroutineScope` to obtain a `CoroutineScope` that may be used to launch ongoing jobs
scoped to the composition in response to event callbacks.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public fun LaunchedEffect(key1: Any?, key2: Any?, block: suspend CoroutineScope.() -> Unit)
```


When `LaunchedEffect` enters the composition it will launch `block` into the composition's
`CoroutineContext`. The coroutine will be `cancelled` and **re-launched** when
`LaunchedEffect` is recomposed with a different `key1` or `key2`. The coroutine will be
`cancelled` when the `LaunchedEffect` leaves the composition.

This function should **not** be used to (re-)launch ongoing tasks in response to callback events
by way of storing callback data in `MutableState` passed to `key`. Instead, see
`rememberCoroutineScope` to obtain a `CoroutineScope` that may be used to launch ongoing jobs
scoped to the composition in response to event callbacks.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public fun LaunchedEffect(
    key1: Any?,
    key2: Any?,
    key3: Any?,
    block: suspend CoroutineScope.() -> Unit,
)
```


When `LaunchedEffect` enters the composition it will launch `block` into the composition's
`CoroutineContext`. The coroutine will be `cancelled` and **re-launched** when
`LaunchedEffect` is recomposed with a different `key1`, `key2` or `key3`. The coroutine will be
`cancelled` when the `LaunchedEffect` leaves the composition.

This function should **not** be used to (re-)launch ongoing tasks in response to callback events
by way of storing callback data in `MutableState` passed to `key`. Instead, see
`rememberCoroutineScope` to obtain a `CoroutineScope` that may be used to launch ongoing jobs
scoped to the composition in response to event callbacks.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public fun LaunchedEffect(vararg keys: Any?, block: suspend CoroutineScope.() -> Unit)
```


When `LaunchedEffect` enters the composition it will launch `block` into the composition's
`CoroutineContext`. The coroutine will be `cancelled` and **re-launched** when
`LaunchedEffect` is recomposed with any different `keys`. The coroutine will be
`cancelled` when the `LaunchedEffect` leaves the composition.

This function should **not** be used to (re-)launch ongoing tasks in response to callback events
by way of storing callback data in `MutableState` passed to `key`. Instead, see
`rememberCoroutineScope` to obtain a `CoroutineScope` that may be used to launch ongoing jobs
scoped to the composition in response to event callbacks.




