blob: cf88a6b2d2841805ddbaf9dd1f4f38202902b724 [file] [log] [blame]
<html devsite="true">
<head>
<title>EffectsKt</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>EffectsKt</h1>
<p>
<pre>public final class <a href="/reference/androidx/compose/runtime/EffectsKt.html">EffectsKt</a></pre>
</p>
<hr>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><span><del><a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</code></div>
<p><strong>This method is deprecated.</strong> DisposableEffect must provide one or more 'key' parameters that define the identity of the DisposableEffect and determine when its previous effect should be disposed and a new effect started for the new key.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Any,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</code></div>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">key1</a></code> and must be reversed or cleaned up if <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">key1</a></code> changes or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Array,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;keys,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</code></div>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">keys</a></code> and must be reversed or cleaned up if any <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">keys</a></code> change or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</code></div>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> and must be reversed or cleaned up if <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> changes, or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key3,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</code></div>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code>, <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key3</a></code> and must be reversed or cleaned up if <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code>, <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key3</a></code> changes, or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br><span><del><a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</code></div>
<p><strong>This method is deprecated.</strong> LaunchedEffect must provide one or more 'key' parameters that define the identity of the LaunchedEffect and determine when its previous effect coroutine should be cancelled and a new effect launched for the new key.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</code></div>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Array,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;keys,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</code></div>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Array,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</code></div>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key3,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</code></div>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#SideEffect(kotlin.Function0)">SideEffect</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;effect)</code></div>
<p>Schedule <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">effect</a></code> to run when the current composition completes successfully and applies changes.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br><a href="/reference/androidx/compose/runtime/EffectsKt.html#rememberCoroutineScope(kotlin.Function0)">rememberCoroutineScope</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/compose/runtime/DisallowComposableCalls.html">DisallowComposableCalls</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a>&gt;&nbsp;getContext<br>)</code></div>
<p>Return a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> bound to this point in the composition using the optional <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code> provided by <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">getContext</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="DisposableEffect-kotlin.Function1-"></a><a name="disposableeffect"></a>
<h3 class="api-name" id="DisposableEffect(kotlin.Function1)">DisposableEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<span><del><a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</pre>
<aside class="caution"><strong>This method is deprecated.</strong><br>DisposableEffect must provide one or more 'key' parameters that define the identity of the DisposableEffect and determine when its previous effect should be disposed and a new effect started for the new key.</aside>
<p>A side effect of composition that must be reversed or cleaned up if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
<p>It is an error to call <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> without at least one <code>key</code> parameter.</p>
</div>
<div class="api-item"><a name="DisposableEffect(kotlin.Any, kotlin.Function1)"></a><a name="DisposableEffect-kotlin.Any-kotlin.Function1-"></a><a name="disposableeffect"></a>
<h3 class="api-name" id="DisposableEffect(kotlin.Any,kotlin.Function1)">DisposableEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Any,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</pre>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">key1</a></code> and must be reversed or cleaned up if <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">key1</a></code> changes or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>'s <em>key</em> is a value that defines the identity of the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>. If a key changes, the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> must <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> its current <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">effect</a></code> and reset by calling <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">effect</a></code> again. Examples of keys include:</p>
<ul>
<li>
<p>Observable objects that the effect subscribes to</p>
</li>
<li>
<p>Unique request parameters to an operation that must cancel and retry if those parameters change</p>
</li>
</ul>
<p><code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> may be used to initialize or subscribe to a key and reinitialize when a different key is provided, performing cleanup for the old operation before initializing the new. For example:</p>
<pre class="prettyprint">
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@Composable
fun UserProfile(userRepository: UserRepository, userRequest: UserDataRequest) {
var userDataState by remember { mutableStateOf&lt;UserDataState&gt;(UserDataState.Loading) }
// If either the repository or request change, we must cancel our old data fetch
// and begin a new data fetch. We will cancel the current data fetch if UserProfile
// leaves the composition.
DisposableEffect(userRepository, userRequest) {
val requestDisposable = userRepository.fetchUserData(
userRequest,
onSuccess = { response -&gt;
userDataState = UserDataState.UserData(response)
},
onError = { throwable -&gt;
userDataState = UserDataState.Error(throwable.message)
}
)
onDispose {
requestDisposable.dispose()
}
}
// ...
}</pre>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> <b>must</b> include an <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">onDispose</a></code> clause as the final statement in its <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">effect</a></code> block. If your operation does not require disposal it might be a <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">SideEffect</a></code> instead, or a <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> if it launches a coroutine that should be managed by the composition.</p>
<p>There is guaranteed to be one call to <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> for every call to <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">effect</a></code>. Both <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Function1)">effect</a></code> and <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> will always be run on the composition's apply dispatcher and appliers are never run concurrent with themselves, one another, applying changes to the composition tree, or running <code><a href="/reference/androidx/compose/runtime/RememberObserver.html">RememberObserver</a></code> event callbacks.</p>
</div>
<div class="api-item"><a name="DisposableEffect(kotlin.Array, kotlin.Function1)"></a><a name="DisposableEffect-kotlin.Array-kotlin.Function1-"></a><a name="disposableeffect"></a>
<h3 class="api-name" id="DisposableEffect(kotlin.Array,kotlin.Function1)">DisposableEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Array,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;keys,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</pre>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">keys</a></code> and must be reversed or cleaned up if any <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">keys</a></code> change or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>'s <em>key</em> is a value that defines the identity of the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>. If a key changes, the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> must <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> its current <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">effect</a></code> and reset by calling <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">effect</a></code> again. Examples of keys include:</p>
<ul>
<li>
<p>Observable objects that the effect subscribes to</p>
</li>
<li>
<p>Unique request parameters to an operation that must cancel and retry if those parameters change</p>
</li>
</ul>
<p><code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> may be used to initialize or subscribe to a key and reinitialize when a different key is provided, performing cleanup for the old operation before initializing the new. For example:</p>
<pre class="prettyprint">
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@Composable
fun UserProfile(userRepository: UserRepository, userRequest: UserDataRequest) {
var userDataState by remember { mutableStateOf&lt;UserDataState&gt;(UserDataState.Loading) }
// If either the repository or request change, we must cancel our old data fetch
// and begin a new data fetch. We will cancel the current data fetch if UserProfile
// leaves the composition.
DisposableEffect(userRepository, userRequest) {
val requestDisposable = userRepository.fetchUserData(
userRequest,
onSuccess = { response -&gt;
userDataState = UserDataState.UserData(response)
},
onError = { throwable -&gt;
userDataState = UserDataState.Error(throwable.message)
}
)
onDispose {
requestDisposable.dispose()
}
}
// ...
}</pre>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> <b>must</b> include an <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">onDispose</a></code> clause as the final statement in its <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">effect</a></code> block. If your operation does not require disposal it might be a <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">SideEffect</a></code> instead, or a <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> if it launches a coroutine that should be managed by the composition.</p>
<p>There is guaranteed to be one call to <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> for every call to <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">effect</a></code>. Both <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Array,kotlin.Function1)">effect</a></code> and <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> will always be run on the composition's apply dispatcher and appliers are never run concurrent with themselves, one another, applying changes to the composition tree, or running <code><a href="/reference/androidx/compose/runtime/RememberObserver.html">RememberObserver</a></code> event callbacks.</p>
</div>
<div class="api-item"><a name="DisposableEffect(kotlin.Any, kotlin.Any, kotlin.Function1)"></a><a name="DisposableEffect-kotlin.Any-kotlin.Any-kotlin.Function1-"></a><a name="disposableeffect"></a>
<h3 class="api-name" id="DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">DisposableEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</pre>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> and must be reversed or cleaned up if <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> changes, or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>'s <em>key</em> is a value that defines the identity of the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>. If a key changes, the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> must <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> its current <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> and reset by calling <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> again. Examples of keys include:</p>
<ul>
<li>
<p>Observable objects that the effect subscribes to</p>
</li>
<li>
<p>Unique request parameters to an operation that must cancel and retry if those parameters change</p>
</li>
</ul>
<p><code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> may be used to initialize or subscribe to a key and reinitialize when a different key is provided, performing cleanup for the old operation before initializing the new. For example:</p>
<pre class="prettyprint">
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@Composable
fun UserProfile(userRepository: UserRepository, userRequest: UserDataRequest) {
var userDataState by remember { mutableStateOf&lt;UserDataState&gt;(UserDataState.Loading) }
// If either the repository or request change, we must cancel our old data fetch
// and begin a new data fetch. We will cancel the current data fetch if UserProfile
// leaves the composition.
DisposableEffect(userRepository, userRequest) {
val requestDisposable = userRepository.fetchUserData(
userRequest,
onSuccess = { response -&gt;
userDataState = UserDataState.UserData(response)
},
onError = { throwable -&gt;
userDataState = UserDataState.Error(throwable.message)
}
)
onDispose {
requestDisposable.dispose()
}
}
// ...
}</pre>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> <b>must</b> include an <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">onDispose</a></code> clause as the final statement in its <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> block. If your operation does not require disposal it might be a <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">SideEffect</a></code> instead, or a <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> if it launches a coroutine that should be managed by the composition.</p>
<p>There is guaranteed to be one call to <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> for every call to <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code>. Both <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> and <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> will always be run on the composition's apply dispatcher and appliers are never run concurrent with themselves, one another, applying changes to the composition tree, or running <code><a href="/reference/androidx/compose/runtime/RememberObserver.html">RememberObserver</a></code> event callbacks.</p>
</div>
<div class="api-item"><a name="DisposableEffect(kotlin.Any, kotlin.Any, kotlin.Any, kotlin.Function1)"></a><a name="DisposableEffect-kotlin.Any-kotlin.Any-kotlin.Any-kotlin.Function1-"></a><a name="disposableeffect"></a>
<h3 class="api-name" id="DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">DisposableEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">DisposableEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key3,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function1&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectScope.html">DisposableEffectScope</a>,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/runtime/DisposableEffectResult.html">DisposableEffectResult</a>&gt;&nbsp;effect<br>)</pre>
<p>A side effect of composition that must run for any new unique value of <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code>, <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key3</a></code> and must be reversed or cleaned up if <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key1</a></code>, <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key2</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">key3</a></code> changes, or if the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> leaves the composition.</p>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>'s <em>key</em> is a value that defines the identity of the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>. If a key changes, the <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> must <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> its current <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> and reset by calling <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> again. Examples of keys include:</p>
<ul>
<li>
<p>Observable objects that the effect subscribes to</p>
</li>
<li>
<p>Unique request parameters to an operation that must cancel and retry if those parameters change</p>
</li>
</ul>
<p><code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> may be used to initialize or subscribe to a key and reinitialize when a different key is provided, performing cleanup for the old operation before initializing the new. For example:</p>
<pre class="prettyprint">
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@Composable
fun UserProfile(userRepository: UserRepository, userRequest: UserDataRequest) {
var userDataState by remember { mutableStateOf&lt;UserDataState&gt;(UserDataState.Loading) }
// If either the repository or request change, we must cancel our old data fetch
// and begin a new data fetch. We will cancel the current data fetch if UserProfile
// leaves the composition.
DisposableEffect(userRepository, userRequest) {
val requestDisposable = userRepository.fetchUserData(
userRequest,
onSuccess = { response -&gt;
userDataState = UserDataState.UserData(response)
},
onError = { throwable -&gt;
userDataState = UserDataState.Error(throwable.message)
}
)
onDispose {
requestDisposable.dispose()
}
}
// ...
}</pre>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code> <b>must</b> include an <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">onDispose</a></code> clause as the final statement in its <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> block. If your operation does not require disposal it might be a <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">SideEffect</a></code> instead, or a <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> if it launches a coroutine that should be managed by the composition.</p>
<p>There is guaranteed to be one call to <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> for every call to <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code>. Both <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Function1)">effect</a></code> and <code><a href="/reference/androidx/compose/runtime/DisposableEffectScope.html#onDispose(kotlin.Function0)">dispose</a></code> will always be run on the composition's apply dispatcher and appliers are never run concurrent with themselves, one another, applying changes to the composition tree, or running <code><a href="/reference/androidx/compose/runtime/RememberObserver.html">RememberObserver</a></code> event callbacks.</p>
</div>
<div class="api-item"><a name="LaunchedEffect-kotlin.coroutines.SuspendFunction1-"></a><a name="launchedeffect"></a>
<h3 class="api-name" id="LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<span><del><a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></del></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</pre>
<aside class="caution"><strong>This method is deprecated.</strong><br>LaunchedEffect must provide one or more 'key' parameters that define the identity of the LaunchedEffect and determine when its previous effect coroutine should be cancelled and a new effect launched for the new key.</aside>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> when the <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> leaves the composition.</p>
<p>It is an error to call <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> without at least one <code>key</code> parameter.</p>
</div>
<div class="api-item"><a name="LaunchedEffect(kotlin.Any, kotlin.coroutines.SuspendFunction1)"></a><a name="LaunchedEffect-kotlin.Any-kotlin.coroutines.SuspendFunction1-"></a><a name="launchedeffect"></a>
<h3 class="api-name" id="LaunchedEffect(kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</pre>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> and <b>re-launched</b> when <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> is recomposed with a different <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.coroutines.SuspendFunction1)">key1</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> when the <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> leaves the composition.</p>
<p>This function should <b>not</b> be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in <code><a href="/reference/androidx/compose/runtime/MutableState.html">MutableState</a></code> passed to <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.coroutines.SuspendFunction1)">key1</a></code>. Instead, see <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">rememberCoroutineScope</a></code> to obtain a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.</p>
</div>
<div class="api-item"><a name="LaunchedEffect(kotlin.Array, kotlin.coroutines.SuspendFunction1)"></a><a name="LaunchedEffect-kotlin.Array-kotlin.coroutines.SuspendFunction1-"></a><a name="launchedeffect"></a>
<h3 class="api-name" id="LaunchedEffect(kotlin.Array,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Array,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;keys,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</pre>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Array,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> and <b>re-launched</b> when <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> is recomposed with any different <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Array,kotlin.coroutines.SuspendFunction1)">keys</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> when the <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> leaves the composition.</p>
<p>This function should <b>not</b> be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in <code><a href="/reference/androidx/compose/runtime/MutableState.html">MutableState</a></code> passed to <code><a href="/reference/androidx/compose/runtime/package-summary.html#key(kotlin.Array,kotlin.Function0)">key</a></code>. Instead, see <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">rememberCoroutineScope</a></code> to obtain a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.</p>
</div>
<div class="api-item"><a name="LaunchedEffect(kotlin.Any, kotlin.Any, kotlin.coroutines.SuspendFunction1)"></a><a name="LaunchedEffect-kotlin.Any-kotlin.Any-kotlin.coroutines.SuspendFunction1-"></a><a name="launchedeffect"></a>
<h3 class="api-name" id="LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</pre>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> and <b>re-launched</b> when <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> is recomposed with a different <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">key1</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">key2</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> when the <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> leaves the composition.</p>
<p>This function should <b>not</b> be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in <code><a href="/reference/androidx/compose/runtime/MutableState.html">MutableState</a></code> passed to <code><a href="/reference/androidx/compose/runtime/package-summary.html#key(kotlin.Array,kotlin.Function0)">key</a></code>. Instead, see <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">rememberCoroutineScope</a></code> to obtain a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.</p>
</div>
<div class="api-item"><a name="LaunchedEffect(kotlin.Any, kotlin.Any, kotlin.Any, kotlin.coroutines.SuspendFunction1)"></a><a name="LaunchedEffect-kotlin.Any-kotlin.Any-kotlin.Any-kotlin.coroutines.SuspendFunction1-"></a><a name="launchedeffect"></a>
<h3 class="api-name" id="LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key1,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key2,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&nbsp;key3,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html">ExtensionFunctionType</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-suspend-function1/index.html">SuspendFunction1</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>,&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;block<br>)</pre>
<p>When <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> enters the composition it will launch <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">block</a></code> into the composition's <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> and <b>re-launched</b> when <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> is recomposed with a different <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">key1</a></code>, <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">key2</a></code> or <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)">key3</a></code>. The coroutine will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html">cancelled</a></code> when the <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code> leaves the composition.</p>
<p>This function should <b>not</b> be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in <code><a href="/reference/androidx/compose/runtime/MutableState.html">MutableState</a></code> passed to <code><a href="/reference/androidx/compose/runtime/package-summary.html#key(kotlin.Array,kotlin.Function0)">key</a></code>. Instead, see <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">rememberCoroutineScope</a></code> to obtain a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.</p>
</div>
<div class="api-item"><a name="SideEffect-kotlin.Function0-"></a><a name="sideeffect"></a>
<h3 class="api-name" id="SideEffect(kotlin.Function0)">SideEffect</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>@<a href="/reference/androidx/compose/runtime/NonRestartableComposable.html">NonRestartableComposable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#SideEffect(kotlin.Function0)">SideEffect</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;effect)</pre>
<p>Schedule <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">effect</a></code> to run when the current composition completes successfully and applies changes. <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">SideEffect</a></code> can be used to apply side effects to objects managed by the composition that are not backed by <code><a href="/reference/androidx/compose/runtime/snapshots/Snapshot.html">snapshots</a></code> so as not to leave those objects in an inconsistent state if the current composition operation fails.</p>
<p><code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">effect</a></code> will always be run on the composition's apply dispatcher and appliers are never run concurrent with themselves, one another, applying changes to the composition tree, or running <code><a href="/reference/androidx/compose/runtime/RememberObserver.html">RememberObserver</a></code> event callbacks. <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">SideEffect</a></code>s are always run after <code><a href="/reference/androidx/compose/runtime/RememberObserver.html">RememberObserver</a></code> event callbacks.</p>
<p>A <code><a href="/reference/androidx/compose/runtime/package-summary.html#SideEffect(kotlin.Function0)">SideEffect</a></code> runs after <b>every</b> recomposition. To launch an ongoing task spanning potentially many recompositions, see <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code>. To manage an event subscription or other object lifecycle, see <code><a href="/reference/androidx/compose/runtime/package-summary.html#DisposableEffect(kotlin.Function1)">DisposableEffect</a></code>.</p>
</div>
<div class="api-item"><a name="rememberCoroutineScope-kotlin.Function0-"></a><a name="remembercoroutinescope"></a>
<h3 class="api-name" id="rememberCoroutineScope(kotlin.Function0)">rememberCoroutineScope</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>public&nbsp;static&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>&nbsp;<a href="/reference/androidx/compose/runtime/EffectsKt.html#rememberCoroutineScope(kotlin.Function0)">rememberCoroutineScope</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/compose/runtime/DisallowComposableCalls.html">DisallowComposableCalls</a> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a>&gt;&nbsp;getContext<br>)</pre>
<p>Return a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> bound to this point in the composition using the optional <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code> provided by <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">getContext</a></code>. <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">getContext</a></code> will only be called once and the same <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> instance will be returned across recompositions.</p>
<p>This scope will be <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/index.html">cancelled</a></code> when this call leaves the composition. The <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html">CoroutineContext</a></code> returned by <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">getContext</a></code> may not contain a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html">Job</a></code> as this scope is considered to be a child of the composition.</p>
<p>The default dispatcher of this scope if one is not provided by the context returned by <code><a href="/reference/androidx/compose/runtime/package-summary.html#rememberCoroutineScope(kotlin.Function0)">getContext</a></code> will be the applying dispatcher of the composition's <code><a href="/reference/androidx/compose/runtime/Recomposer.html">Recomposer</a></code>.</p>
<p>Use this scope to launch jobs in response to callback events such as clicks or other user interaction where the response to that event needs to unfold over time and be cancelled if the composable managing that process leaves the composition. Jobs should never be launched into <b>any</b> coroutine scope as a side effect of composition itself. For scoped ongoing jobs initiated by composition, see <code><a href="/reference/androidx/compose/runtime/package-summary.html#LaunchedEffect(kotlin.coroutines.SuspendFunction1)">LaunchedEffect</a></code>.</p>
<p>This function will not throw if preconditions are not met, as composable functions do not yet fully support exceptions. Instead the returned scope's <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html">CoroutineScope.coroutineContext</a></code> will contain a failed <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html">Job</a></code> with the associated exception and will not be capable of launching child jobs.</p>
</div>
</div>
</body>
</html>