Hey, I believe that the documentation for `derived...
# compose
l
Hey, I believe that the documentation for
derivedStateOf
is misleading, and it that SideEffect should be declared in
remember
using no keys to really benefit from its caching mechanism. Here’s a documentation using keys with remember with derivedStateOf:
Copy code
<https://developer.android.com/jetpack/compose/side-effects#derivedstateof>
And here’s a documentation that doesn’t use keys in remembers:
<https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#derivedStateOf(kotlin.Function0)>
Any thoughts on that?
z
I don’t see what either of these examples have to do with
SideEffect
l
Nah, i just used name Side effect in the meaning of derivedStateOf to avoid duplication in the initial message ;)
z
So you’re thinking it would make sense to turn
highPriorityKeywords
into a state (eg using
rememberUpdatedState
) and then get rid of the remember keys around
derivedStateOf
?
l
Just the other way round - having remember using no keys, as
derivedStateOf
knows when to reevaluate itself. That would make perfect sense for me
z
That’s what I meant - but you can’t do that without turning the
highPriorityKeywords
argument into a state otherwise the
derivedStateOf
lambda would just capture the initial value and never update if the caller passed a different list in
Passing
todoTasks
as a key shouldn’t actually change behavior in this case, I believe, because that list is always the same object. So even if the contents of the list change, it shouldn’t invalidate the
remember
, and the
derivedStateOf
will handle the update itself as you’d probably want.
Which means that if you stored
highPriorityKeywords
in a state and got rid of the keys, it wouldn’t save you anything when highPriorityKeywords changed since the only for that to happen would mean that the function was already being reexecuted.