I am trying to fetch API data with peging 3 library. I am following this tutorial. However, the API is called multiple times. I assume it's because of this code in compose:
val documentList = dashboardViewModel.getBreakingNews().collectAsLazyPagingItems()
Here is the code of view model
fun getBreakingNews(
): Flow<PagingData<Data>> = getNews().cachedIn(viewModelScope)
fun getNews() = Pager(
config = PagingConfig(
pageSize = 10,
),
pagingSourceFactory = {
DocPagingSource(arkeliyaApiService)
}
).flow
I want to declare Flow<PagingData<Data>> like I did with other APIs
For example
private val _listofReqDoc = MutableStateFlow<List<Data>>(listOf())
val listofReqDoc = _listofReqDoc.asStateFlow()
As simple as