derive-the-flag-dont-store-and-correct-it

Installation
SKILL.md

Derive it, don't store a guess and patch it

A value fully determined by state the composable already collects sometimes still gets its own slot — remember or rememberSaveable { mutableStateOf(...) } — written to by a LaunchedEffect that watches the real source and copies a derived answer into it. That slot is strictly worse than reading the source directly, for the two reasons below: an initial guess renders before anything can correct it, and the "obvious" fix to the guess does not reach a process that already saved the old one.

// adapted — trimmed to the two relevant declarations; both are otherwise verbatim
// before
var isShowMiniPlayer by rememberSaveable { mutableStateOf(true) }
// ...
LaunchedEffect(nowPlayingData) {
    isShowMiniPlayer = !(nowPlayingData?.mediaItem == null || nowPlayingData?.mediaItem == GenericMediaItem.EMPTY)
}
Installs
2
GitHub Stars
35
First Seen
6 days ago
derive-the-flag-dont-store-and-correct-it — maxrave-dev/kotlin-footguns