Handle User Intents & Actions
Drive state changes from UI events.
The UI Asks, You Decide
When a user taps a button, the UI should not run logic itself. It sends an intent to the ViewModel, which decides what happens.
Name Your Intents
Model each possible user action as a sealed class. Now every intent the screen can fire is named, typed and impossible to misspell.
sealed class HomeIntent {
object Refresh : HomeIntent()
data class Search(val q: String) : HomeIntent()
}All lessons in this course
- A Cross-Platform ViewModel Base
- Expose UI State as StateFlow
- Handle User Intents & Actions
- Bind the ViewModel to Each UI