Knowledgebase

Managing State in Compose Print

  • mobiledevelopment, mobile, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Data driving the interface.

WHAT STATE IS HERE

Observable values that trigger recomposition when changed.

WHAT REMEMBERING DOES

Retains a value across recompositions.

WHAT IT DOES NOT SURVIVE

Configuration changes, unless the saving variant is used.

WHAT THAT MEANS

Rotation loses it, unless handled.

WHAT STATE HOISTING IS

Moving state up to a caller, so the composable receives the value and reports events.

WHY IT MATTERS

It makes composables reusable, testable and previewable.

WHAT THE PATTERN IS

State flows down; events flow up.

WHAT TO KEEP IN A VIEW MODEL

State surviving configuration changes and belonging to the screen.

WHAT TO KEEP LOCAL

Transient interface state: whether something is expanded, scroll position.

WHAT TO AVOID

Deriving values and storing them, rather than computing during composition Mutating collections in place, which is not observed State duplicated in several places

WHY MUTATION IS NOT OBSERVED

Compose compares references, so a mutated list appears unchanged.

WHAT TO DO INSTEAD

Produce a new value.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot