Introduction
Imagine a bakery with multiple kitchens. You have a main recipe, the parent composable, for delicious cookies. This recipe calls for steps like mixing dry ingredients, creaming butter and sugar, and baking. The steps are the child composables.
Instead of each step having a separate stock of ingredients (state), what if you could keep a central pantry for the entire bakery, the Compose hierarchy? The central pantry would be located at a higher level in the bakery and accessible to all steps that need the ingredients.
This is state hoisting. In this lesson, you’ll learn about state hoisting and its purpose in Jetpack Compose. You’ll also learn about the best practices for hoisting state and when not to hoist state.