Hello guys. I have a small doubt. In the below cod...
# compose
a
Hello guys. I have a small doubt. In the below code, I have written a function
AudioWidgetItem
and I am passing a lambda
onPostClicked
in it. Now when I am invoking this lambda on
line 149
then this function is getting recomposed again and again on some action (even though hash code of this lambda is coming same as printed in
line 144
). But when I am commenting out this lambda invocation at
line 149
then unnecessary recomposition of this function doesn't happen. I am not able to understand the reason behind this behaviour
s
Is there a chance your onPostClicked changes some state which is hoisted out which results in this function being called again since one of the other inputs has changed?
a
Nope. I debugged more and found that actionData is the culprit here. If I am wrapping actionData in some stable wrapper class and passing that to
AudioWidgetItem
and
onPostClicked
then problems solves
s
Okay so
JsonElement
was not Stable. Is that from kotlinx.serialization? Also did you need to make onPostClicked stable too? I actually don’t know if lambda functions are inferred as stable or not.
a
Its from
gson
Not sure if we can make lambdas as stable. I had to use remember block with lambda to keep its instance same or it'll create different hashcode each time if I use it directly
n
Do you happen to have a simple repro that you can share? We struggle a lot with lambda recompositions and it would be nice to have a playground to investigate deeper.