From the course: Android Compose with Kotlin
Unlock this course with a free trial
Join today to access over 24,300 courses taught by industry experts.
Use the remember function - Kotlin Tutorial
From the course: Android Compose with Kotlin
Use the remember function
- [Instructor] You can hardly see Compose code without a remember function in the hierarchy, and likely you've seen variations, one as a standard variable and the other using Kotlin property delegation. The outcome is the same, although the syntax differs. Many developers find the property delegation syntax preferable, however. Onto the remember function. Remember is used to store values inside of a composition. This is important when we consider the lifecycle of a composable. In each composition, a composable can enter the composition, be recomposed several times, and then exit the composition. Without properly storing or caching state, it would be like writing on a chalkboard, only to erase everything and write it all again. That's a massive waste of time and resources. Likewise, without the use of the remember function, Compose could run expensive operations repeatedly during recomposition, causing the performance of your app to suffer. Let's move over to Android Studio to analyze…