tezvyn:

How would you architect state-driven UI with ViewModel and Compose?

Source: developer.android.comadvanced

Tests unidirectional data flow and state hoisting. Model screen state as an immutable data class, expose StateFlow from ViewModel, and collect it in Compose so events flow up and state down. Red flag: exposing mutable state or putting logic in Composables.

Tests whether you understand unidirectional data flow and the ViewModel as the single source of truth in Compose. A strong answer models the entire screen as an immutable data class, exposes it via StateFlow from the ViewModel, and collects it in the Composable using collectAsState. Events are sent back up through callbacks or a channel. Red flag: using multiple LiveData streams, exposing mutable state, or keeping business logic inside Composables instead of hoisting it to the ViewModel.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How would you architect state-driven UI with ViewModel and Compose? · Tezvyn