Showing Paginated Data
LazyColumnWithLoading<T>
LazyColumnWithLoading Composable: A Reusable Component for Paginated Data
Purpose:
The LazyColumnWithLoading composable is a reusable component designed to efficiently handle paginated data within a LazyColumn. It automatically manages loading states, error handling, and data rendering.
Parameters:
- remoteData: A- RemoteData<T>object representing the paginated data.
- modifier: A- Modifierto apply to the surface.
- itemView: A composable function that takes an item and returns the content to be displayed.
Functionality:
- Loading State: - Checks if - remoteDatais- None(initial state or loading).
- If - None, displays a loading view.
 
- Error State: - Checks if - remoteDatais- Some(Left(ErrMessage)).
- If - Left, displays an error view.
 
- Content State: - Checks if - remoteDatais- Some(Right(Page<T>)).
- If - Right, renders the paginated data using a- LazyColumn.
 
Key Features:
- Automatic Loading: Handles loading states and displays a loading indicator while data is being fetched. 
- Error Handling: Displays an error message if an error occurs during data fetching. 
- Pagination: Efficiently renders paginated data using a - LazyColumn.
- Customizable: Allows you to customize the loading and error views. 
Example Usage:
Kotlin
LazyColumnWithLoading(
    remoteData = todoViewModel.todos.collectAsState().value,
    itemView = { todo -> TodoItemView(todo) }
)Additional Notes:
- The - RemoteDatatype is used to represent the data, which includes the paginated data and potential errors.
- The - LazyColumnis used to efficiently render the paginated content, avoiding unnecessary rendering of off-screen items.
- You can customize the loading and error views by providing your own composables to the - LazyColumnWithLoadingcomponent.
By using LazyColumnWithLoading, you can simplify the process of handling paginated data in your KMM applications and provide a better user experience.
Last updated