# rememberStackState

## Functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/rememberStackState.composable#rememberStackState(kotlin.Int)(initialTopItem: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates and remembers a `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` for a `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)`. |

## Functions

### rememberStackState

Artifact: [androidx.xr.glimmer:glimmer](https://developer.android.com/jetpack/androidx/releases/xr-glimmer) [View Source](https://cs.android.com/search?q=file:androidx/xr/glimmer/stack/StackState.kt+function:rememberStackState) Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
@Composable
fun rememberStackState(initialTopItem: @IntRange(from = 0) Int = 0): StackState
```

Creates and remembers a `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` for a `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)`.

The returned `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` is remembered across compositions and can be used to control or observe the state of a `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)`. It's essential to pass this state to the `state` parameter of the corresponding `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` composable.

Note: Properties of the state will only be correctly populated after the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` it is associated with has been composed for the first time.

Warning: A single `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` instance must not be shared across multiple `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` composables.

| Parameters |
|---|---|
| `initialTopItem: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The index of the item to show at the top of the stack initially. Must be non-negative. Defaults to 0. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` |   |
| `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` |   |