https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
h

he-dev

11/11/2023, 3:36 PM
Is there a way to observe a
State
property from another property? Let's say I
var firstName by mutableStateOf("")
and would like to make another property depend on its state being at the same time also a state. This means I'd like to observe its changes and handle them accordingly. Same way as composables know when something changes.
k

kevin.cianfarini

11/11/2023, 3:37 PM
This is better asked in #compose for future reference, but you'll want to use
derivedStateOf
for this
1
h

he-dev

11/11/2023, 3:41 PM
Oh, you're right. I should have asked it there, sorry 😇 I didn't expect it to be that easy 🤯
k

kevin.cianfarini

11/11/2023, 4:58 PM
No problem! Happy to help.