<div class='type'>Function</div>


<a id='references'></a>


<h2 id="derivedstateof-calculation">derivedStateOf</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
@StateFactoryMarker
public fun <T> derivedStateOf(calculation: () -> T): State<T>
```


Creates a `State` object whose `State.value` is the result of `calculation`. The result of
calculation will be cached in such a way that calling `State.value` repeatedly will not cause
`calculation` to be executed multiple times, but reading `State.value` will cause all `State`
objects that got read during the `calculation` to be read in the current `Snapshot`, meaning that
this will correctly subscribe to the derived state objects if the value is being read in an
observed context such as a `Composable` function. Derived states without mutation policy trigger
updates on each dependency change. To avoid invalidation on update, provide suitable
`SnapshotMutationPolicy` through `derivedStateOf` overload.

#### Parameters

| | |
| --- | --- |
| calculation | the calculation to create the value this state object represents. |






<hr class="docs-overload-divider">


<h2 id="derivedstateof-policy-calculation">derivedStateOf</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
@StateFactoryMarker
public fun <T> derivedStateOf(policy: SnapshotMutationPolicy<T>, calculation: () -> T): State<T>
```


Creates a `State` object whose `State.value` is the result of `calculation`. The result of
calculation will be cached in such a way that calling `State.value` repeatedly will not cause
`calculation` to be executed multiple times, but reading `State.value` will cause all `State`
objects that got read during the `calculation` to be read in the current `Snapshot`, meaning that
this will correctly subscribe to the derived state objects if the value is being read in an
observed context such as a `Composable` function.

#### Parameters

| | |
| --- | --- |
| policy | mutation policy to control when changes to the `calculation` result trigger update. |
| calculation | the calculation to create the value this state object represents. |