compose-state-hoisting

Guide state hoisting and unidirectional data flow in Kotlin Compose UIs.

61|3|Updated Mar 1, 2024
One-click install
npx skills add https://github.com/alexandru/social-publish --skill compose-state-hoisting-alexandru
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-state-hoisting
Source: https://github.com/alexandru/social-publish/tree/main/.agents/skills/compose-state-hoisting
Command: npx skills add https://github.com/alexandru/social-publish --skill compose-state-hoisting-alexandru

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Compose UI state is often scattered, leading to tangled logic and fragile lifecycles. This skill guides developers to apply clear state ownership, unidirectional data flow, and appropriate saving strategies in Kotlin Compose across Android, Multiplatform, and Web targets.

Core Features & Use Cases

  • Provides a decision framework for hoisting UI state to the lowest common ancestor.
  • Recommends lifespans (remember, retain, rememberSaveable, rememberSerializable) and stateless composable patterns.
  • Includes practical guidance for per-screen state holders and derived/stateful logic with safe patterns.

Quick Start

Read the guidance and apply a lowest-common-ancestor hoist, using remember-based state holders for complex UI interactions.

Frequently Asked Questions about compose-state-hoisting

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

FAQPage Schema
How do I implement state hoisting in Kotlin Compose for unidirectional data flow?

State hoisting in Kotlin Compose moves state ownership to the lowest common ancestor, creating stateless composables and enforcing unidirectional data flow to prevent tangled UI logic and fragile lifecycles.

What is the difference between rememberSaveable and rememberSerializable for Compose UI state?

rememberSaveable and rememberSerializable are state lifespans in Compose UI. This skill provides a decision framework to choose the appropriate saving strategy for retaining UI state across configuration changes or lifecycle events.

Does this state hoisting guidance work for Compose Multiplatform and Web projects?

Yes, this state hoisting guidance applies to Compose Multiplatform and Web projects. It supports clear state ownership and unidirectional data flow across Android, Multiplatform, and Compose for Web targets.

When should I create per-screen state holders in Jetpack Compose?

Create per-screen state holders in Jetpack Compose when managing complex UI interactions. This skill recommends using remember-based state holders to safely handle derived and stateful logic within a unidirectional data flow.

Why does my Compose UI state get lost during configuration changes?

Compose UI state is lost during configuration changes when incorrect saving strategies are used. Applying appropriate lifespans like rememberSaveable or rememberSerializable ensures state persistence across lifecycle events.