SideEffect

Functions summary

Unit

Schedule effect to run when the current composition completes successfully and applies changes.

Cmn
Unit

Schedule effect to run as a side effect for any new unique value of key1.

Cmn
Unit
@Composable
@NonRestartableComposable
SideEffect(vararg keys: Any?, effect: () -> Unit)

Schedule effect to run as a side effect for any new unique keys.

Cmn
Unit
@Composable
@NonRestartableComposable
SideEffect(key1: Any?, key2: Any?, effect: () -> Unit)

Schedule effect to run as a side effect for any new unique value of key1 or key2.

Cmn
Unit
@Composable
@NonRestartableComposable
SideEffect(key1: Any?, key2: Any?, key3: Any?, effect: () -> Unit)

Schedule effect to run as a side effect for any new unique value of key1, key2, or key3.

Cmn

Functions

SideEffect

@Composable
@NonRestartableComposable
@ExplicitGroupsComposable
fun SideEffect(effect: () -> Unit): Unit

Schedule effect to run when the current composition completes successfully and applies changes. SideEffect can be used to apply side effects to objects managed by the composition that are not backed by snapshots so as not to leave those objects in an inconsistent state if the current composition operation fails.

effect 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 RememberObserver event callbacks. SideEffects are always run after RememberObserver event callbacks.

A SideEffect runs after every recomposition when invoked without any keys. To only perform the effect once, use an overload of SideEffect that accepts a key. To launch an ongoing task spanning potentially many recompositions, see LaunchedEffect. To manage an event subscription or other object lifecycle, see DisposableEffect.

Note: For all overloads of SideEffect, the effect is executed after all DisposableEffect and RememberObserver callbacks are dispatched. Effects are executed in the order that they appear in the composition hierarchy (following an in-order traversal).

SideEffect

@Composable
@NonRestartableComposable
fun SideEffect(key1: Any?, effect: () -> Unit): Unit

Schedule effect to run as a side effect for any new unique value of key1.

A SideEffect's key is a value that defines the identity of the SideEffect. When a SideEffect recomposes, its effect will only execute if its key differs from the previously provided value.

When using the overload of this function that doesn't accept keys, the effect will execute on every recomposition. This overload is preferred when you have one-shot work that doesn't require the coroutine afforded by LaunchedEffect, or the disposal afforded by DisposableEffect.

Note: For all overloads of SideEffect, the effect is executed after all DisposableEffect and RememberObserver callbacks are dispatched. Effects are executed in the order that they appear in the composition hierarchy (following an in-order traversal).

Parameters
key1: Any?

A key input; if recomposed with a new value from the previous key, effect will be scheduled.

effect: () -> Unit

The effect that will execute when this composition completes successfully and is applying changes.

SideEffect

@Composable
@NonRestartableComposable
fun SideEffect(vararg keys: Any?, effect: () -> Unit): Unit

Schedule effect to run as a side effect for any new unique keys.

A SideEffect's keys are values that defines the identity of the SideEffect. When a SideEffect recomposes, its effect will only execute if any of its keys differ from their previously provided value.

When using the overload of this function that doesn't accept keys, the effect will execute on every recomposition. This overload is preferred when you have one-shot work that doesn't require the coroutine afforded by LaunchedEffect, or the disposal afforded by DisposableEffect.

Note: For all overloads of SideEffect, the effect is executed after all DisposableEffect and RememberObserver callbacks are dispatched. Effects are executed in the order that they appear in the composition hierarchy (following an in-order traversal).

Parameters
vararg keys: Any?

Key inputs; if recomposed with a different list of keys, effect will be scheduled.

effect: () -> Unit

The effect that will execute when this composition completes successfully and is applying changes.

SideEffect

@Composable
@NonRestartableComposable
fun SideEffect(key1: Any?, key2: Any?, effect: () -> Unit): Unit

Schedule effect to run as a side effect for any new unique value of key1 or key2.

A SideEffect's keys are values that defines the identity of the SideEffect. When a SideEffect recomposes, its effect will only execute if any of its keys differ from their previously provided value.

When using the overload of this function that doesn't accept keys, the effect will execute on every recomposition. This overload is preferred when you have one-shot work that doesn't require the coroutine afforded by LaunchedEffect, or the disposal afforded by DisposableEffect.

Note: For all overloads of SideEffect, the effect is executed after all DisposableEffect and RememberObserver callbacks are dispatched. Effects are executed in the order that they appear in the composition hierarchy (following an in-order traversal).

Parameters
key1: Any?

A key input; if recomposed with a new value from the previous key, effect will be scheduled.

key2: Any?

A second key input; if recomposed with a new value from the previous key, effect will be scheduled.

effect: () -> Unit

The effect that will execute when this composition completes successfully and is applying changes.

SideEffect

@Composable
@NonRestartableComposable
fun SideEffect(key1: Any?, key2: Any?, key3: Any?, effect: () -> Unit): Unit

Schedule effect to run as a side effect for any new unique value of key1, key2, or key3.

A SideEffect's keys are values that defines the identity of the SideEffect. When a SideEffect recomposes, its effect will only execute if any of its keys differ from their previously provided value.

When using the overload of this function that doesn't accept keys, the effect will execute on every recomposition. This overload is preferred when you have one-shot work that doesn't require the coroutine afforded by LaunchedEffect, or the disposal afforded by DisposableEffect.

Note: For all overloads of SideEffect, the effect is executed after all DisposableEffect and RememberObserver callbacks are dispatched. Effects are executed in the order that they appear in the composition hierarchy (following an in-order traversal).

Parameters
key1: Any?

A key input; if recomposed with a new value from the previous key, effect will be scheduled.

key2: Any?

A second key input; if recomposed with a new value from the previous key, effect will be scheduled.

key3: Any?

A third key input; if recomposed with a new value from the previous key, effect will be scheduled.

effect: () -> Unit

The effect that will execute when this composition completes successfully and is applying changes.