> For the complete documentation index, see [llms.txt](https://docs.galex.dev/yamvil/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.galex.dev/yamvil/usage/fragment.md).

# Fragment

Example of an MVI Fragment implemented with Yamvil.

```kotlin
class DashboardFragment: MVIFragment<DashboardUiState, DashboardUiEvent>() {

    override val viewModel: DashboardViewModel by viewModels()
    override fun observeUiState(uiState: DashboardUiState) {
        when(uiState.state) {
            DashboardUiState.ContentState.Loading -> onLoading()
            is DashboardUiState.ContentState.Content -> onContent(uiState.state)
            DashboardUiState.ContentState.Error -> onError()
        }

        uiState.onAction { action ->
            when(action) {
                DashboardUiAction.NavigateToNext -> navigateToNext()
            }
        }
    }

    private fun navigateToNext() {
        // Do something with navigateToNext
    }

    private fun onLoading() {
        // Do something with loading
    }

    private fun onContent(content: DashboardUiState.ContentState.Content) {
        // Do something with content
    }

    private fun onError() {
        // Do something with error
    }
}
```

Note that as `DashboardUiState` implements `Actionable` , we need to use the  `onAction` function to consume only once the `UiAction`:

```kotlin
uiState.onAction { action ->
    when(action) {
        DashboardUiAction.NavigateToNext -> navigateToNext()
    }
}
```
