# ReusableComposition

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

  ```
  sealed interface ReusableComposition : Composition
  ```
Known direct subclasses [PausableComposition](https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausableComposition)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausableComposition` | A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausableComposition` is a sub-composition that can be composed incrementally as it supports being paused and resumed. |

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ReusableComposition` is a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` that can be reused for different composable content.

This interface is used by components that have to synchronize lifecycle of parent and child compositions and efficiently reuse the nodes emitted by `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ReusableComposeNode.composable#ReusableComposeNode(kotlin.Function0,kotlin.Function1)`.

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ReusableComposition#deactivate()()` Deactivate all observation scopes in composition and remove all remembered slots while preserving nodes in place. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ReusableComposition#setContentWithReuse(kotlin.Function0)(content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Update the composition with the content described by the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ReusableComposition#setContentWithReuse(kotlin.Function0)` composable. | Cmn |

| ### Inherited functions |
|---|
| From [androidx.compose.runtime.Composition](https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition) |---|---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#dispose()()` Clear the hierarchy that was created from the composition and release resources allocated for composition. | Cmn | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#setContent(kotlin.Function0)(content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Update the composition with the content described by the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#setContent(kotlin.Function0)` composable. | Cmn | |

| ### Inherited properties |
|---|
| From [androidx.compose.runtime.Composition](https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition) |---|---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#hasInvalidations()` Returns true if any pending invalidations have been scheduled. | Cmn | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#isDisposed()` True if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#dispose()` has been called. | Cmn | |

## Public functions

### deactivate

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

```
fun deactivate(): Unit
```

Deactivate all observation scopes in composition and remove all remembered slots while preserving nodes in place. The composition can be re-activated by calling `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#setContent(kotlin.Function0)` with a new content.

### setContentWithReuse

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

```
fun setContentWithReuse(content: @Composable () -> Unit): Unit
```

Update the composition with the content described by the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ReusableComposition#setContentWithReuse(kotlin.Function0)` composable. After this has been called the changes to produce the initial composition has been calculated and applied to the composition.

This method forces this composition into "reusing" state before setting content. In reusing state, all remembered content is discarded, and nodes emitted by `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ReusableComposeNode.composable#ReusableComposeNode(kotlin.Function0,kotlin.Function1)` are re-used for the new content. The nodes are only reused if the group structure containing the node matches new content.

Will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` if the composition has been disposed.

| Parameters |
|---|---|
| `content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A composable function that describes the content of the composition. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | thrown in the composition has been `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#dispose()`d. |