# produceState

Common/AllAndroid/JVMNative/C/iOSJavaScript

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.coroutines.SuspendFunction1)(initialValue: T, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time without a defined data source. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)( initialValue: T, mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time without a defined data source. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)(initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)( initialValue: T, vararg keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)( initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)( initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)( initialValue: T, vararg keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)( initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)( initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)( initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)( initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key4: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)( initialValue: T, key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, key4: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>, producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`. | Cmn |

## Functions

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <T : Any?> produceState(initialValue: T, producer: suspend ProduceStateScope<T>.() -> Unit): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time without a defined data source.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.coroutines.SuspendFunction1)` leaves the composition. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` conflates values; no change will be observable if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` is used to set a value that is `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to its old value, and observers may only see the latest value if several values are set in rapid succession. This can be changed by providing a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    mutationPolicy: SnapshotMutationPolicy<T>,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time without a defined data source.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` leaves the composition. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is used to control how changes are reported and merged in the returned state. If not specified, the default behavior is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#structuralEqualityPolicy()`, which conflates values that are `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to each other. Note observers may only see the latest value if several values are set in rapid succession. This is especially true when reading the returned state in composition, as composition executes with the latest values from a snapshot rather than composing once with each intermediate value of a state.

The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is only used when initializing the underlying state object. If the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` changes after creating the state, the state and the producer are unaffected and will continue collecting in the previously returned state with the original `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>` | A policy used to control how changes are handled in the returned state |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <T : Any?> produceState(initialValue: T, key1: Any?, producer: suspend ProduceStateScope<T>.() -> Unit): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` changes, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` conflates values; no change will be observable if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` is used to set a value that is `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to its old value, and observers may only see the latest value if several values are set in rapid succession. This can be changed by providing a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    vararg keys: Any?,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` conflates values; no change will be observable if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` is used to set a value that is `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to its old value, and observers may only see the latest value if several values are set in rapid succession. This can be changed by providing a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `vararg keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A list of keys that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,kotlin.coroutines.SuspendFunction1)` lambda |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    key1: Any?,
    mutationPolicy: SnapshotMutationPolicy<T>,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` changes, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is used to control how changes are reported and merged in the returned state. If not specified, the default behavior is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#structuralEqualityPolicy()`, which conflates values that are `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to each other. Note observers may only see the latest value if several values are set in rapid succession. This is especially true when reading the returned state in composition, as composition executes with the latest values from a snapshot rather than composing once with each intermediate value of a state.

Changes to the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` are ignored.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>` | A policy used to control how changes are handled in the returned state |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    key1: Any?,
    key2: Any?,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` conflates values; no change will be observable if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` is used to set a value that is `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to its old value, and observers may only see the latest value if several values are set in rapid succession. This can be changed by providing a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    vararg keys: Any?,
    mutationPolicy: SnapshotMutationPolicy<T>,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is used to control how changes are reported and merged in the returned state. If not specified, the default behavior is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#structuralEqualityPolicy()`, which conflates values that are `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to each other. Note observers may only see the latest value if several values are set in rapid succession. This is especially true when reading the returned state in composition, as composition executes with the latest values from a snapshot rather than composing once with each intermediate value of a state.

The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is only used when initializing the underlying state object. If the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` changes after creating the state, the state and the producer are unaffected and will continue collecting in the previously returned state with the original `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `vararg keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A list of keys that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Array,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>` | A policy used to control how changes are handled in the returned state |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    key1: Any?,
    key2: Any?,
    mutationPolicy: SnapshotMutationPolicy<T>,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is used to control how changes are reported and merged in the returned state. If not specified, the default behavior is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#structuralEqualityPolicy()`, which conflates values that are `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to each other. Note observers may only see the latest value if several values are set in rapid succession. This is especially true when reading the returned state in composition, as composition executes with the latest values from a snapshot rather than composing once with each intermediate value of a state.

The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is only used when initializing the underlying state object. If the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` changes after creating the state, the state and the producer are unaffected and will continue collecting in the previously returned state with the original `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>` | A policy used to control how changes are handled in the returned state |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    key1: Any?,
    key2: Any?,
    key3: Any?,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` conflates values; no change will be observable if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` is used to set a value that is `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to its old value, and observers may only see the latest value if several values are set in rapid succession. This can be changed by providing a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    key1: Any?,
    key2: Any?,
    key3: Any?,
    mutationPolicy: SnapshotMutationPolicy<T>,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is used to control how changes are reported and merged in the returned state. If not specified, the default behavior is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#structuralEqualityPolicy()`, which conflates values that are `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to each other. Note observers may only see the latest value if several values are set in rapid succession. This is especially true when reading the returned state in composition, as composition executes with the latest values from a snapshot rather than composing once with each intermediate value of a state.

The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is only used when initializing the underlying state object. If the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` changes after creating the state, the state and the producer are unaffected and will continue collecting in the previously returned state with the original `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>` | A policy used to control how changes are handled in the returned state |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    key1: Any?,
    key2: Any?,
    key3: Any?,
    key4: Any?,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` conflates values; no change will be observable if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` is used to set a value that is `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to its old value, and observers may only see the latest value if several values are set in rapid succession. This can be changed by providing a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `key4: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.coroutines.SuspendFunction1)` lambda |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |

### produceState

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+function:produceState)

```
@Composable
fun <T : Any?> produceState(
    initialValue: T,
    key1: Any?,
    key2: Any?,
    key3: Any?,
    key4: Any?,
    mutationPolicy: SnapshotMutationPolicy<T>,
    producer: suspend ProduceStateScope<T>.() -> Unit
): State<T>
```

Return an observable `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that produces values over time from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is launched when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` enters the composition and is cancelled when `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` leaves the composition. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)`, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` change, a running `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` will be cancelled and re-launched for the new source. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` should use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#value()` to set new values on the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

The given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is used to control how changes are reported and merged in the returned state. If not specified, the default behavior is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#structuralEqualityPolicy()`, which conflates values that are `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/equals.html` to each other. Note observers may only see the latest value if several values are set in rapid succession. This is especially true when reading the returned state in composition, as composition executes with the latest values from a snapshot rather than composing once with each intermediate value of a state.

The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` is only used when initializing the underlying state object. If the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` changes after creating the state, the state and the producer are unaffected and will continue collecting in the previously returned state with the original `https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy`.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` may be used to observe either suspending or non-suspending sources of external data, for example:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.produceState

val uiState by
    produceState<UiState<List<Person>>>(UiState.Loading, viewModel) {
        viewModel.people.map { UiState.Data(it) }.collect { value = it }
    }

when (val state = uiState) {
    is UiState.Loading -> Text("Loading...")
    is UiState.Data ->
        Column {
            for (person in state.data) {
                Text("Hello, ${person.name}")
            }
        }
}
```

```kotlin
import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }
```

| Parameters |
|---|---|
| `initialValue: T` | The value that the returned state will initially contain |
| `key1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `key2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `key3: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `key4: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A key that, when changed, will restart the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#produceState(kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy,kotlin.coroutines.SuspendFunction1)` lambda |
| `mutationPolicy: https://developer.android.com/reference/kotlin/androidx/compose/runtime/SnapshotMutationPolicy<T>` | A policy used to control how changes are handled in the returned state |
| `producer: suspend https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope<T>.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A suspending lambda that defines what values are emitted to the returned state |