Kotlin Language

Modeling UI state

kotlin
sealed interface UiState<out T> {
    data object Loading : UiState<Nothing>
    data class Success<T>(val data: T) : UiState<T>
    data class Error(val message: String) : UiState<Nothing>
}

Explicit states make screens easier to reason about because the compiler can help you handle every case.

Lesson complete?Use the next lesson to continue the learning path.