compose-state-authoring

Guide correct local state management in Jetpack Compose components.

13|Updated Jun 24, 2021
One-click install
npx skills add https://github.com/costular/Minitask --skill compose-state-authoring-costular
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-state-authoring
Source: https://github.com/costular/Minitask/tree/main/.agents/skills/compose-state-authoring
Command: npx skills add https://github.com/costular/Minitask --skill compose-state-authoring-costular

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill helps developers avoid common pitfalls in managing local state within Jetpack Compose, ensuring UI components behave as expected and remain performant.

Core Features & Use Cases

  • Local State Guidance: Offers best practices for using remember, mutableStateOf, and @ReadOnlyComposable.
  • State Management Best Practices: Provides rules for var usage within composable functions and understanding the @ReadOnlyComposable annotation.
  • Use Case: A developer is creating a form with Jetpack Compose and wants to ensure that the state of the form persists and updates correctly when user interactions occur.

Quick Start

Analyze your Jetpack Compose code using the compose-state-authoring skill to identify and fix potential state management issues.

Frequently Asked Questions about compose-state-authoring

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

FAQPage Schema
How do I manage local state in Jetpack Compose without losing data on recomposition?

To manage local state in Jetpack Compose safely, use `remember` with `mutableStateOf` to ensure state persists across recompositions and updates the UI correctly when user interactions occur.

When should I use the @ReadOnlyComposable annotation in Compose?

The `@ReadOnlyComposable` annotation is used when a composable function only reads state without modifying it. It helps optimize Jetpack Compose performance by skipping unnecessary recompositions for read-only UI components.

What is the best way to handle form state updates in Jetpack Compose?

The best way to handle form state is using `remember` and `mutableStateOf` within your composable functions. This ensures the form's local state persists and updates correctly during user interactions like text input.

Why does my Compose UI state reset or behave unexpectedly during recomposition?

Compose UI state resets when `mutableStateOf` is used without `remember`. Wrapping your state in `remember` prevents the state from being recreated during recomposition, fixing unexpected behavior and data loss.

Can I use var directly inside a Jetpack Compose function for state management?

Using `var` directly inside a composable function does not trigger recomposition. You must use `var` with `mutableStateOf` and `remember` to properly manage local state and ensure UI updates in Jetpack Compose.