{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

MutableState

public interface MutableState<T extends Object> extends State

Known direct subclasses
MutableDoubleState

A value holder where reads to the doubleValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

MutableFloatState

A value holder where reads to the floatValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

MutableIntState

A value holder where reads to the intValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

MutableLongState

A value holder where reads to the longValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

ProduceStateScope

Receiver scope for use with produceState.

SnapshotMutableState

A mutable value holder where reads to the value property during the execution of a Composable function, the current RecomposeScope will be subscribed to changes of that value.


A mutable value holder where reads to the value property during the execution of a Composable function, the current RecomposeScope will be subscribed to changes of that value. When the value property is written to and changed, a recomposition of any subscribed RecomposeScopes will be scheduled. If value is written to with the same value, no recompositions will be scheduled.

See also
State
mutableStateOf

Summary

Public methods

abstract @NonNull T
abstract @NonNull Function1<@NonNull T, Unit>
abstract @NonNull T
abstract void
setValue(@NonNull T value)

Extension functions

default final void
<T extends Object> SnapshotStateKt.setValue(
    @NonNull MutableState<@NonNull T> receiver,
    Object thisObj,
    @NonNull KProperty<@NonNull ?> property,
    @NonNull T value
)

Permits property delegation of vars using by for MutableState.

Public methods

component1

abstract @NonNullcomponent1()

component2

abstract @NonNull Function1<@NonNull T, Unitcomponent2()

getValue

abstract @NonNullgetValue()

setValue

abstract void setValue(@NonNull T value)

Extension functions

SnapshotStateKt.setValue

default final void <T extends Object> SnapshotStateKt.setValue(
    @NonNull MutableState<@NonNull T> receiver,
    Object thisObj,
    @NonNull KProperty<@NonNull ?> property,
    @NonNull T value
)

Permits property delegation of vars using by for MutableState.

import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember

var count by remember { mutableStateOf(0) }

Text(text = "You clicked $count times")
Button(onClick = { count = count + 1 }) {
    Text("Click me")
}