Jetpack Compose — When Should I Use DerivedStateOf?
derivedStateOf — a really common question we see is where and when is the correct place to use this API? The answer to this question is <strong class="ki jk">derivedStateOf {}</strong> should be used when your state or key is changing more than you want to update your UI. Or in other words, derivedStateOf is like distinctUntilChanged from Kotlin Flows or other similar reactive frameworks. Remember that Composables recompose when the Compose state object they read, changes. derivedStateOf allows you to create a new state object that changes only as much as you need. Let’s take a look at an example. Here we have a username field and a button that enables when the…
Share