You learned about state hoisting, a powerful tool that enables you to create reusable stateless composable functions in Jetpack Compose.
With great power comes great responsibility! Here are some things you should keep in mind when implementing state hoisting.
Hoist to the Lowest Common Ancestor
The state should be hoisted to the lowest common parent of all the composables that use that state. As you write composables for your app UI, identify state variables multiple composables use. Lift the state variable to the closest parent composable that all those children share, the lowest common ancestor.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.