https://kotlinlang.org logo
#compose
Title
# compose
e

elye

01/21/2022, 12:39 PM
Seems like using
derivedStateOf
is more superior than
remember(value)
given it can reduce the unnecessary recomposition. I wonder is there any downside using
remember { derivedStateOf { value } }
as oppose to
remember(value)
? More elaboration of my question in https://stackoverflow.com/questions/70801388/is-there-downside-replacing-all-remembervalue-with-remember-derivedstateof
👀 2
d

Dominaezzz

01/21/2022, 2:03 PM
Derived state only works when there's mutable state in the lambda, and it only gets invalidated based on that and nothing else.
You almost always want to use remember in compostable functions and derived state in view models.
There are exceptions of course but that's the general rule.
z

Zach Klippenstein (he/him) [MOD]

01/21/2022, 4:37 PM
Derived state also does more bookkeeping so if you don't need it, it's more efficient to use a simpler approach.
🙏 1
🙏🏽 1
2 Views