Function

mutableStateOf

Return a new MutableState initialized with the passed in value The MutableState class is a single value holder whose reads and writes are observed by Compose.

SimpleStateSample

@Sampled
@Composable
fun SimpleStateSample() {
    val count = remember { mutableStateOf(0) }

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

DestructuredStateSample

@Sampled
@Composable
fun DestructuredStateSample() {
    val (count, setCount) = remember { mutableStateOf(0) }

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

observeUserSample

@Suppress("unused")
@Sampled
fun observeUserSample() {

stateSample

@Sampled
@Suppress("DEPRECATION") // b/552879150
fun stateSample() {
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: