---
title: "rememberLazyGridState"
description: "Creates a [LazyGridState] that is remembered across compositions.

Changes to the provided initial values will **not** result in the state being recreated or
changed in any way if it has already been created."
type: "composable"
---

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


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

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


```kotlin
@Composable
fun rememberLazyGridState(
    initialFirstVisibleItemIndex: Int = 0,
    initialFirstVisibleItemScrollOffset: Int = 0,
): LazyGridState
```


Creates a `LazyGridState` that is remembered across compositions.

Changes to the provided initial values will **not** result in the state being recreated or
changed in any way if it has already been created.

#### Parameters

| | |
| --- | --- |
| initialFirstVisibleItemIndex | the initial value for `LazyGridState.firstVisibleItemIndex` |
| initialFirstVisibleItemScrollOffset | the initial value for `LazyGridState.firstVisibleItemScrollOffset` |




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


```kotlin
@ExperimentalFoundationApi
@Composable
fun rememberLazyGridState(
    initialFirstVisibleItemIndex: Int = 0,
    initialFirstVisibleItemScrollOffset: Int = 0,
    prefetchStrategy: LazyGridPrefetchStrategy = remember { LazyGridPrefetchStrategy() },
): LazyGridState
```


Creates a `LazyGridState` that is remembered across compositions.

Changes to the provided initial values will **not** result in the state being recreated or
changed in any way if it has already been created.

#### Parameters

| | |
| --- | --- |
| initialFirstVisibleItemIndex | the initial value for `LazyGridState.firstVisibleItemIndex` |
| initialFirstVisibleItemScrollOffset | the initial value for `LazyGridState.firstVisibleItemScrollOffset` |
| prefetchStrategy | the `LazyGridPrefetchStrategy` to use for prefetching content in this grid |




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


```kotlin
@ExperimentalFoundationApi
@Composable
fun rememberLazyGridState(
    cacheWindow: LazyLayoutCacheWindow,
    initialFirstVisibleItemIndex: Int = 0,
    initialFirstVisibleItemScrollOffset: Int = 0,
): LazyGridState
```


Creates a `LazyGridState` that is remembered across compositions.

Changes to the provided initial values will **not** result in the state being recreated or
changed in any way if it has already been created.

#### Parameters

| | |
| --- | --- |
| cacheWindow | specifies the size of the ahead and behind window to be used as per `LazyLayoutCacheWindow`. |
| initialFirstVisibleItemIndex | the initial value for `LazyGridState.firstVisibleItemIndex` |
| initialFirstVisibleItemScrollOffset | the initial value for `LazyGridState.firstVisibleItemScrollOffset` |





