DisposableEffect

@ComposableContract(restartable = false)
fun DisposableEffect(effect: DisposableEffectScope.() -> DisposableEffectDisposable)
@ComposableContract(restartable = false)
fun DisposableEffect(subject: Any?, effect: DisposableEffectScope.() -> DisposableEffectDisposable)

A side effect of composition that must run for any new unique value of subject and must be reversed or cleaned up if subject changes or if the DisposableEffect leaves the composition.

A DisposableEffect's subject is a value that defines the identity of the DisposableEffect. If a subject changes, the DisposableEffect must dispose its current effect and reset by calling effect again. Examples of subjects include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

DisposableEffect may be used to initialize or subscribe to a subject and reinitialize when a different subject is provided, performing cleanup for the old operation before initializing the new. For example:

Samples

androidx.compose.runtime.samples.disposableEffectSample
@ComposableContract(restartable = false)
fun DisposableEffect(subject1: Any?, subject2: Any?, effect: DisposableEffectScope.() -> DisposableEffectDisposable)

A side effect of composition that must run for any new unique value of subject1 or subject2 and must be reversed or cleaned up if subject1 or subject2 changes, or if the DisposableEffect leaves the composition.

A DisposableEffect's subject is a value that defines the identity of the DisposableEffect. If a subject changes, the DisposableEffect must dispose its current effect and reset by calling effect again. Examples of subjects include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

DisposableEffect may be used to initialize or subscribe to a subject and reinitialize when a different subject is provided, performing cleanup for the old operation before initializing the new. For example:

Samples

androidx.compose.runtime.samples.disposableEffectSample
@ComposableContract(restartable = false)
fun DisposableEffect(subject1: Any?, subject2: Any?, subject3: Any?, effect: DisposableEffectScope.() -> DisposableEffectDisposable)

A side effect of composition that must run for any new unique value of subject1, subject2 or subject3 and must be reversed or cleaned up if subject1, subject2 or subject3 changes, or if the DisposableEffect leaves the composition.

A DisposableEffect's subject is a value that defines the identity of the DisposableEffect. If a subject changes, the DisposableEffect must dispose its current effect and reset by calling effect again. Examples of subjects include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

DisposableEffect may be used to initialize or subscribe to a subject and reinitialize when a different subject is provided, performing cleanup for the old operation before initializing the new. For example:

Samples

androidx.compose.runtime.samples.disposableEffectSample
@ComposableContract(restartable = false)
fun DisposableEffect(vararg subjects: Any?, effect: DisposableEffectScope.() -> DisposableEffectDisposable)

A side effect of composition that must run for any new unique value of subjects and must be reversed or cleaned up if any subjects change or if the DisposableEffect leaves the composition.

A DisposableEffect's subject is a value that defines the identity of the DisposableEffect. If a subject changes, the DisposableEffect must dispose its current effect and reset by calling effect again. Examples of subjects include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

DisposableEffect may be used to initialize or subscribe to a subject and reinitialize when a different subject is provided, performing cleanup for the old operation before initializing the new. For example:

Samples

androidx.compose.runtime.samples.disposableEffectSample