> Documentation index: https://developer.android.com/reference/llms.txt

# collectAsLazyPagingItems

Common/All

## Functions summary

|---|---|---|
| `LazyPagingItems<T>` | `@Composable <T : Any> Flow<PagingData<T>>.collectAsLazyPagingItems( context: CoroutineContext )` Collects values from this `Flow` of `PagingData` and represents them inside a `LazyPagingItems` instance. | Cmn |

## Functions

### Flow.collectAsLazyPagingItems

Cmn Artifact: [androidx.paging:paging-compose](https://developer.android.com/jetpack/androidx/releases/paging.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/paging/compose/LazyPagingItems.kt+function:collectAsLazyPagingItems) Added in [3.2.0](https://developer.android.com/jetpack/androidx/releases/paging.md.txt#3.2.0)

```
@Composable
fun <T : Any> Flow<PagingData<T>>.collectAsLazyPagingItems(
    context: CoroutineContext = EmptyCoroutineContext
): LazyPagingItems<T>
```

Collects values from this `Flow` of `PagingData` and represents them inside a `LazyPagingItems` instance. The `LazyPagingItems` instance can be used for lazy foundations such as `LazyListScope.items` in order to display the data obtained from a `Flow` of `PagingData`.

```kotlin
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.sp
import androidx.paging.LoadState
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.samples.util.TestBackend

val myBackend = remember { TestBackend(DATA, transform = { "[Item $it is from backend]" }) }

val pager = remember {
    Pager(
        PagingConfig(pageSize = myBackend.pageSize, enablePlaceholders = true, maxSize = 200)
    ) {
        myBackend.getPagingSource()
    }
}

val lazyPagingItems = pager.flow.collectAsLazyPagingItems()

LazyColumn {
    if (lazyPagingItems.loadState.refresh == LoadState.Loading) {
        item {
            Text(
                text = "Waiting for items to load from the backend",
                modifier =
                    Modifier.fillMaxWidth().wrapContentWidth(Alignment.CenterHorizontally),
            )
        }
    }

    items(count = lazyPagingItems.itemCount) { index ->
        val item = lazyPagingItems[index]
        Text("Index=$index: $item", fontSize = 20.sp)
    }

    if (lazyPagingItems.loadState.append == LoadState.Loading) {
        item {
            CircularProgressIndicator(
                modifier =
                    Modifier.fillMaxWidth().wrapContentWidth(Alignment.CenterHorizontally)
            )
        }
    }
}
```

| Parameters |
|---|---|
| `context: CoroutineContext = EmptyCoroutineContext` | the `CoroutineContext` to perform the collection of `PagingData` and `CombinedLoadStates`. |