I migrated from Paging 2 to Paging 3 library and now I use the PagingSource
to load pages of data from the server. But I have trouble understanding the getRefreshKey
method that has to be overriden there. I found some code samples how to implement it depending on the key used to fetch subsequent pages but I still don't get it. Based on these samples I wrote the following code:
override fun getRefreshKey(state: PagingState<Pair<String, String>, User>): Pair<String, String>? {
return state.anchorPosition?.let { anchorPosition ->
state.closestPageToPosition(anchorPosition)?.prevKey
}
}
But it doesn't change a thing if I make it to always return null:
override fun getRefreshKey(state: PagingState<Pair<String, String>, User>): Pair<String, String>? = null
So is there a reason why I can't just choose the simplest solution possible? Or is there a use case that I don't see?