# SnapshotInstanceObservers

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/tooling/SnapshotObserver.kt+class:androidx.compose.runtime.snapshots.tooling.SnapshotInstanceObservers) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.8.0) Common/All
- Cmn

  ```
  @ExperimentalComposeRuntimeApi
  class SnapshotInstanceObservers
  ```

*** ** * ** ***

The return result of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/tooling/SnapshotObserver#onPreCreate(androidx.compose.runtime.snapshots.Snapshot,kotlin.Boolean)` allowing the reads and writes performed in the newly created snapshot to be observed

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/tooling/SnapshotInstanceObservers#SnapshotInstanceObservers(kotlin.Function1,kotlin.Function1)( readObserver: ((https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?, writeObserver: ((https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? )` | Cmn |

| ### Public properties |
|---|---|---|
| `((https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/tooling/SnapshotInstanceObservers#readObserver()` Called whenever a state is read in the snapshot. | Cmn |
| `((https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/tooling/SnapshotInstanceObservers#writeObserver()` Called just before a state object is written to the first time in the snapshot or a nested mutable snapshot. | Cmn |

## Public constructors

### SnapshotInstanceObservers

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

```
SnapshotInstanceObservers(
    readObserver: ((Any) -> Unit)? = null,
    writeObserver: ((Any) -> Unit)? = null
)
```

## Public properties

### readObserver

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

```
val readObserver: ((Any) -> Unit)?
```

Called whenever a state is read in the snapshot. This is called before the read observer passed to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot#takeSnapshot(kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot#takeMutableSnapshot(kotlin.Function1,kotlin.Function1)`.

This method is called in the same thread that reads snapshot state.

### writeObserver

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

```
val writeObserver: ((Any) -> Unit)?
```

Called just before a state object is written to the first time in the snapshot or a nested mutable snapshot. This might be called several times for the same object if nested mutable snapshots are created as the unmodified value may be needed by the nested snapshot so a new copy is created. This is not called for each write, only when the write results in the object be recorded as being modified requiring a copy to be made before the write completes. This is called before the write has been applied to the instance.

This is called before the write observer passed to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/snapshots/Snapshot#takeMutableSnapshot(kotlin.Function1,kotlin.Function1)`.

This method is called in the same thread that writes to the snapshot state.