kmp-compose-state-container

Guides selection of remember, rememberSaveable, or ViewModel for Compose Multiplatform state.

2|Updated Jun 6, 2026
One-click install
npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-compose-state-container-ronjunevaldoz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kmp-compose-state-container
Source: https://github.com/ronjunevaldoz/kmp-agent-skills/tree/main/skills/kmp-compose-state-container
Command: npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-compose-state-container-ronjunevaldoz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Choosing the wrong state container in Compose Multiplatform causes lost form input on rotation, crashes from oversized Bundles, and ViewModels bloated with ephemeral UI state. This Skill provides a decision framework for picking the correct container based on what must survive recomposition, configuration changes, and process death. ## Core Features & Use Cases - Survival Matrix: A clear table showing what remember, rememberSaveable, ViewModel, and SavedStateHandle each survive across recomposition, config changes, and process death. - Decision Tree: A step-by-step flow for routing state to the right container based on async needs, Bundle-safety, and sharing scope. - Advanced Patterns: Covers custom Saver implementations, nav-graph-scoped ViewModels, derivedStateOf, snapshotFlow, and rememberUpdatedState with correct usage and anti-patterns. - Use Case: A user complains their registration form loses all input on screen rotation — the Skill identifies remember as the wrong container and recommends rememberSaveable or a ViewModel with validation logic. ## Quick Start Ask the agent which state container to use for a form field that must survive screen rotation in a Compose Multiplatform screen.

Frequently Asked Questions about kmp-compose-state-container

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use remember vs rememberSaveable vs ViewModel in Compose?▼

Use remember for ephemeral UI state like dropdown toggles, rememberSaveable for form input that must survive rotation, and ViewModel for business data or async operations. The decision depends on what must survive recomposition, config changes, and process death.

How do I save a custom type with rememberSaveable?▼

Write a custom Saver that maps your type to Bundle-safe primitives, then pass it via rememberSaveable(stateSaver = yourSaver). The Saver defines save and restore lambdas converting between your type and a Map of primitives.

Does rememberSaveable work on Desktop and iOS in Compose Multiplatform?▼

Config-change survival behavior of rememberSaveable and ViewModel applies only on Android. On Desktop and iOS, composable lifetime is tied to the window or view lifecycle, so plan state survival accordingly for cross-platform needs.

Why does my app crash when using rememberSaveable with a large list?▼

Bundles have a size limit around 1 MB, and storing large collections triggers TransactionTooLargeException on Android. Store only IDs in rememberSaveable or SavedStateHandle and reload the actual data from a repository or cache.

How do I share a ViewModel across multiple screens in Navigation Compose?▼

Scope the ViewModel to a nav graph by obtaining the graph's back-stack entry with navController.getBackStackEntry and passing it as the viewModelStoreOwner to koinViewModel. The ViewModel then survives navigation between screens within that graph.

Why is my LaunchedEffect calling a stale lambda?▼

A LaunchedEffect(Unit) captures the lambda value at launch time, so recompositions with a new lambda are ignored. Wrap the lambda with rememberUpdatedState and call the current reference inside the effect to always use the latest value.