A scope that manages a shared headless Composition for running one or more state transformations created via launchTransform.

Summary

Public functions

DisposableState<T>
<T : Any?> launchTransform(initialState: T, onUpdate: @Composable (T) -> T)

Launches a Composable onUpdate transformation in this TransformScope and returns its result as a DisposableState.

Cmn

Public functions

launchTransform

fun <T : Any?> launchTransform(initialState: T, onUpdate: @Composable (T) -> T): DisposableState<T>

Launches a Composable onUpdate transformation in this TransformScope and returns its result as a DisposableState.

This function bridges reactive Compose state (or Flows collected as state) into a continuously updated State object outside a traditional Compose UI hierarchy. The transform block is automatically recomposed whenever any Compose state it reads is updated, and the newly returned value is pushed into the resulting State.

Calling DisposableState.dispose removes this transformation from the TransformScope so that it is no longer recomposed in the shared Composition.

Parameters
initialState: T

The initial value to populate the returned DisposableState before the first composition completes.

onUpdate: @Composable (T) -> T

The Composable block that computes the updated value of type T.

Returns
DisposableState<T>

A DisposableState containing the latest result of the onUpdate block.