Jetpack Compose: how it works, and how to answer it in an interview

    Articles on Jetpack Compose from first principles to production: how recomposition, remember and key() really work, the slot table, interview questions, and building a production-ready app with Kotlin and Compose.

    How Compose works

    The runtime behind the declarative UI.

    Interview preparation

    Building and learning Compose

    Questions people ask

    Does Jetpack Compose redraw everything when state changes?

    No. Recomposition is Compose selectively revisiting previously composed code because something that code depends on has changed. Compose works out what actually needs to run again.

    Why do list items sometimes keep the wrong state in Compose?

    If you insert an item at the top of a list, the items after it shift position, and remembered state can end up attached to the wrong item. key() tells Compose how to identify each item, so state follows the item.

    What does remember actually do?

    It associates a value with a location in the composition and returns the existing value while that identity remains appropriate. If the composable leaves the composition, its slots are removed and the value is lost.

    Go further