Understanding stateful and stateless composable functions
In this section, I will show you the difference between stateful and stateless composable functions. To understand why this is important, let’s first focus on the term state.
In the previous chapters, I described state as data that can change over time. Where the data is held (e.g., a SQLite database, a file, or a value inside an object) does not matter. What is important is that the UI must always show the current data. Therefore, if a value changes, the UI must be notified. To achieve this, we use observable types. This is not specific to Jetpack Compose and is a common pattern in many frameworks, programming languages, and platforms. For example, Kotlin supports observables through property delegates. Let’s see how they work.
Please note that the following code snippet is not an Android app. While you could execute it in Android Studio using a Scratch File, there’s a much easier way – Kotlin...