Currently, I'm doing this to fetch items when list...
# compose-desktop
a
Currently, I'm doing this to fetch items when list reaches a specific index (I don't know if the naming is correct)
Copy code
@NonRestartableComposable
@Composable
inline fun <T> PagingEffect(
    iterable: Iterable<T>,
    currentIndex: Int,
    crossinline block: (T) -> Unit,
) {
    SideEffect {
        iterable.runOnIndex(currentIndex, block)
    }
}

inline fun <T> Iterable<T>.runOnIndex(currentIndex: Int, block: (T) -> Unit) {
    withIndex().last().apply {
        if (index == currentIndex)
            block(value)
    }
}
And using it like this:
Copy code
LazyColumn {
    val list = listOf<Item>()
    itemsIndexed(list) { index, item ->
        PagingEffect(list, index) {
            // Request more items
        }
    }
}
Is there a better way?