# withLocalRetainedValuesStore

Common/All

## Functions summary

|---|---|---|
| `R` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/withLocalRetainedValuesStore.composable#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)( store: https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore, content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> R )` Installs the given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` over the provided `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` and returns the result of the lambda. | Cmn |

## Functions

### withLocalRetainedValuesStore

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

```
@Composable
fun <R : Any?> withLocalRetainedValuesStore(
    store: RetainedValuesStore,
    content: @Composable () -> R
): R
```

Installs the given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` over the provided `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` and returns the result of the lambda. Use to install a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore` in all non-unit returning `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` lambdas. For content that returns `Unit`, use `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/LocalRetainedValuesStoreProvider.composable#LocalRetainedValuesStoreProvider(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` instead.

This method of installing a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore` has the same guarantees and semantics as `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/LocalRetainedValuesStoreProvider.composable#LocalRetainedValuesStoreProvider(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` with the addition of a return value.

```kotlin
import androidx.compose.runtime.Composable
import androidx.compose.runtime.retain.retain
import androidx.compose.runtime.retain.retainManagedRetainedValuesStore
import androidx.compose.runtime.retain.withLocalRetainedValuesStore

@Composable
fun Content(presenter: Presenter) {
    /* ... */
}

/**
 * Retains a Presenter to compose some [Content] with model-view-presenter patterns. The
 * Presenter is retained and passed to the content, but is wrapped separately in
 * [withLocalRetainedValuesStore] to give the presenter and content different retention
 * lifespans.
 */
@Composable
fun PresentedContent(visible: Boolean) {
    val retainedValuesStore = retainManagedRetainedValuesStore()

    if (visible) {
        val presenter =
            withLocalRetainedValuesStore(retainedValuesStore) {
                // Retain presenter for future reuse
                retain { Presenter() }
            }

        // Show content from the Presenter, but don't retain values in
        // the presenter's store
        Content(presenter)
    }
}
```

| Parameters |
|---|---|
| `store: https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore` | The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore` to install as the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#LocalRetainedValuesStore()` |
| `content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> R` | The Composable content that the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` will be installed for. This content block is invoked immediately in-place. |

| Returns |
|---|---|
| `R` | The result of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#withLocalRetainedValuesStore(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/LocalRetainedValuesStoreProvider.composable#LocalRetainedValuesStoreProvider(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)` |   |