<h2 id="rememberstackstate-initialtopitem">rememberStackState</h2>

<div class='sourceset sourceset-android'>Android</div>

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

Creates and remembers a [StackState](/jetpack-compose/androidx.xr.glimmer/glimmer/classes/StackState) for a [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack).

The returned [StackState](/jetpack-compose/androidx.xr.glimmer/glimmer/classes/StackState) is remembered across compositions and can be used to control or observe
the state of a [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack). It's essential to pass this state to the `state` parameter of the
corresponding [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack) composable.

Note: Properties of the state will only be correctly populated after the [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack) it is
associated with has been composed for the first time.

Warning: A single [StackState](/jetpack-compose/androidx.xr.glimmer/glimmer/classes/StackState) instance must not be shared across multiple [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack)
composables.

#### Parameters

| | |
| --- | --- |
| initialTopItem | The index of the item to show at the top of the stack initially. Must be non-negative. Defaults to 0. |