Unlock AI power-ups β upgrade and save 20%!
Use code STUBE20OFF during your first month after signup. Upgrade now β

By Philipp Lackner
Published Loading...
N/A views
N/A likes
F Tier: remember / mutableStateOf
π This approach is considered the worst due to state loss during configuration changes (like screen rotation) or process death.
βοΈ While `rememberSavable` can mitigate process death issues, it requires states to be serializable, which limits complex data types.
π The major downside is that state logic is mixed inside composables, necessitating UI tests (APK build, device installation) for testing simple logic.
S Tier: MVI Pattern (Single State Data Class + Sealed Actions)
π This approach ranks S tier when applied correctly because it keeps the UI clean, always receiving a single state object and one `onAction` lambda.
π State updates rely on immutable copying of the current state, requiring caution to avoid race conditions.
π« A critical rule is not to pass the entire state instance to child composables to prevent unnecessary recompositions.
π Boilerplate is shifted to the state/view model, where every new state field or action requires definition in the state class/sealed interface and handling in the view model's `when` expression.
A Tier: Traditional MVVM (Separate State Flows)
β¨ Advantageous for easily combining and deriving new state flows because each state field (e.g., `items`, `isLoading`) is exposed as an independent observable state flow.
β It results in significant boilerplate in Compose; a screen with 20 changing values requires 20 parameters passed to the composable and 20 corresponding callbacks bubbled up.
π While it can survive configuration changes and process death via the View Model, the high volume of individual parameters in Compose reduces its ranking from potential S tier (where it excelled with Fragments).
C Tier: Sealed Class for State (Mutually Exclusive States)
β
Offers exhaustiveness checking via `when` expressions, forcing handling of every possible state (Idle, Loading, Success, Error), which prevents invalid UI states like showing both loading spinner and items simultaneously.
π Its applicability is severely limited as it assumes states are mutually exclusive, failing for complex screens loading multiple independent data sets concurrently.
π§© Updating a single field within a complex state (e.g., within a `Success` state holding multiple fields) often requires type checks and creating an entirely new instance, adding friction.
A Tier: Combining State Flows (Hybrid Approach)
π‘ This hybrid model uses private mutable state flows in the View Model but exposes a single derived state data class to the UI via a `combine` block.
π‘οΈ This naturally eliminates race conditions as it avoids relying on manual state copying; the `combine` block ensures the exposed state is always complete and correct when any private flow emits.
β οΈ The main limitation arises when combining more than five state flows, as the default `combine` overload returns an array, forcing manual destructuring and unsafe type casting.
Key Points & Insights
β‘οΈ The MVI pattern is recommended as the go-to pattern for Jetpack Compose due to its clean UI separation, despite shifting boilerplate to the state layer.
β‘οΈ Avoid using `remember` with `mutableStateOf` for application state as it fails to survive configuration changes unless using `rememberSavable`, which has serialization limitations.
β‘οΈ For the MVVM approach, while deriving state is easy, the necessity to pass numerous individual parameters down to composables makes it verbose in the Compose context compared to passing a single state object.
β‘οΈ The Combining State Flows method offers derived state for free but becomes cumbersome when exceeding the default capacity of the `combine` function overload (around five flows).
πΈ Video summarized with SummaryTube.com on Mar 05, 2026, 16:50 UTC
Find relevant products on Amazon related to this video
As an Amazon Associate, we earn from qualifying purchases
Full video URL: youtube.com/watch?v=Zwmcr6duzhY
Duration: 22:34

Summarize youtube video with AI directly from any YouTube video page. Save Time.
Install our free Chrome extension. Get expert level summaries with one click.