# StateRecord

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/snapshots/Snapshot.kt+class:androidx.compose.runtime.snapshots.StateRecord) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  abstract class StateRecord
  ```

*** ** * ** ***

Snapshot local value of a state object.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#StateRecord()()` | Cmn |
| `[StateRecord](https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#StateRecord(kotlin.Int))(id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Use snapshotId: Long constructor instead | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#StateRecord(androidx.compose.runtime.snapshots.SnapshotId)(snapshotId: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotId)` | Cmn |

| ### Public functions |
|---|---|---|
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#assign(androidx.compose.runtime.snapshots.StateRecord)(value: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord)` Copy the value into this state record from another for the same state object. | Cmn |
| `abstract https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#create()()` Create a new state record for the same state object. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#create(androidx.compose.runtime.snapshots.SnapshotId)(snapshotId: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/SnapshotId)` Create a new state record for the same state object and provided `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#create(androidx.compose.runtime.snapshots.SnapshotId)`. | Cmn |

| ### Extension functions |
|---|---|---|
| `T` | `<T : https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord> T.https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject)(state: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject)` Return the current readable state record for the current snapshot. | Cmn |
| `T` | `<T : https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord> T.https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot)(state: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject, snapshot: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot)` Return the current readable state record for the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot)`. | Cmn |
| `inline R` | `<T : https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> T.[withCurrent](https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(kotlin.Function1))(block: (r) -> R)` **This function is deprecated.** Use the overload that has a StateObject parameter instead; for example, next.withCurrent(this) { ... } | Cmn |
| `inline R` | `<T : https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> T.https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)(state: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject, block: (r) -> R)` Provides a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` with the current record, without notifying any read observers. | Cmn |
| `inline R` | `<T : https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> T.https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)(state: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject, block: T.() -> R)` Call `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` with a writable state record for the given record. | Cmn |
| `inline R` | `<T : https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> T.https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot,kotlin.Function1)( state: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject, snapshot: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot, block: T.() -> R )` Call `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot,kotlin.Function1)` with a writable state record for `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot,kotlin.Function1)` of the given record. | Cmn |

## Public constructors

### StateRecord

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
StateRecord()
```

### StateRecord

Cmn Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.8.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.8.0)

```
[StateRecord](https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#StateRecord(kotlin.Int))(id: Int)
```

> [!CAUTION]
> **This function is deprecated.**   
> Use snapshotId: Long constructor instead

### StateRecord

Cmn

```
StateRecord(snapshotId: SnapshotId)
```

## Public functions

### assign

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
abstract fun assign(value: StateRecord): Unit
```

Copy the value into this state record from another for the same state object.

### create

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
abstract fun create(): StateRecord
```

Create a new state record for the same state object. Consider also implementing the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#create()` overload that provides snapshotId for faster record construction when snapshot id is known.

### create

Cmn

```
open fun create(snapshotId: SnapshotId): StateRecord
```

Create a new state record for the same state object and provided `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#create(androidx.compose.runtime.snapshots.SnapshotId)`. This allows to implement an optimized version of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#create(androidx.compose.runtime.snapshots.SnapshotId)` to avoid accessing `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#currentSnapshot()` when snapshot id is known. The default implementation provides a backwards compatible behavior, and should be overridden if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord` subclass supports this optimization.

## Extension functions

### T.readable

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/snapshots/Snapshot.kt+function:readable)

```
fun <T : StateRecord> T.readable(state: StateObject): T
```

Return the current readable state record for the current snapshot. It is assumed that `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject)` is the first record of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject)`

### T.readable

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/snapshots/Snapshot.kt+function:readable)

```
fun <T : StateRecord> T.readable(state: StateObject, snapshot: Snapshot): T
```

Return the current readable state record for the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot)`. It is assumed that `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot)` is the first record of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).readable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot)`

### T.withCurrent

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/snapshots/Snapshot.kt+function:withCurrent)

```
inline fun <T : StateRecord, R : Any?> T.[withCurrent](https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateRecord#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(kotlin.Function1))(block: (r) -> R): R
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the overload that has a StateObject parameter instead; for example, next.withCurrent(this) { ... }

Provides a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(kotlin.Function1)` with the current record, without notifying any read observers.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#readable(androidx.compose.runtime.snapshots.StateRecord,androidx.compose.runtime.snapshots.SnapshotId,androidx.compose.runtime.snapshots.SnapshotIdSet)` |   |

### T.withCurrent

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/snapshots/Snapshot.kt+function:withCurrent)

```
inline fun <T : StateRecord, R : Any?> T.withCurrent(state: StateObject, block: (r) -> R): R
```

Provides a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` with the current record, without notifying any read observers.

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/StateObject` | the state object for which the receiver is a state record. It is assumed that `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` is the first record of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` (e.g. `next.withCurrent(this) { ... }`). |
| `block: (r) -> R` | a block to be evaluated with the current state record as its parameter. The result of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` is the result of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)`. It is expected, but not required, that the result of block is either `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` or derives it value from the content of the state record. |

| Returns |
|---|---|
| `R` | the result returned by the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).withCurrent(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` lambda. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#readable(androidx.compose.runtime.snapshots.StateRecord,androidx.compose.runtime.snapshots.SnapshotId,androidx.compose.runtime.snapshots.SnapshotIdSet)` |   |

### T.writable

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/snapshots/Snapshot.kt+function:writable)

```
inline fun <T : StateRecord, R : Any?> T.writable(state: StateObject, block: T.() -> R): R
```

Call `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,kotlin.Function1)` with a writable state record for the given record. It is assumed that this is called for the first state record in a state object. A record is writable if it was created in the current mutable snapshot.

### T.writable

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/snapshots/Snapshot.kt+function:writable)

```
inline fun <T : StateRecord, R : Any?> T.writable(
    state: StateObject,
    snapshot: Snapshot,
    block: T.() -> R
): R
```

Call `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot,kotlin.Function1)` with a writable state record for `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/package-summary#(androidx.compose.runtime.snapshots.StateRecord).writable(androidx.compose.runtime.snapshots.StateObject,androidx.compose.runtime.snapshots.Snapshot,kotlin.Function1)` of the given record. It is assumed that this is called for the first state record in a state object. If the snapshot is read-only calling this will throw.