What is the right “pattern” to access the data of ...
# compose
g
What is the right “pattern” to access the data of an observedAsState
StateFlow
inside a lambda inside a
@Composable
? Using
rememberUpdatedState
or is there anything else I should be doing instead?
s
Yeah sounds about right, if that lambda is only created once and doesn’t change on recomposition you can do that.
🙏 1
g
It is created and passed into a custom modifier applied on a
LazyColumn
s
Yeah I was just referring how some of them also are provided keys, like the PointerInput or
LaunchedEffect
etc you can instead provide the keys that the lambda refers to. Otherwise
rememberUpdatedState
should be fine afaik.
today i learned 1
g
It’s kind of scary I have to say! The reference you pass as a parameter in a
Composable
is not the value you get inside a lambda in that
Composable
🤯 I think I get the recomposition idea but it’s like you have to think in 4 dimensions for what looks like a normal function!
s
Hey I’m totally with you in general. But after a point when it “clicks” you unlock a ton of possibilities. With plenty more to learn of course 😄 Regarding the “…is not the value you get inside a lambda…” comment, what do you mean exactly? It is the same value that you have passed to the composable at least initially. It’s just that if the value is updated and the lambda isn’t (or
rememberUpdatedState
isn’t used) then it becomes “stale” in a sense. That’s what you’re referring to right?
g
Yes indeed, I was really surprised by this behavior
But when you think about the sequence of recompositions (4d) and that a lambda is after all just an anonymous class, it made sense and I understood I have to use
rememberUpdatedState
. I hope I’ll be getting that click soon enough 😄
That’s also what
items
is getting from
LazyList
inside
LazyColumn
which proved me that was right
But still, feels weird somehow
👍 1
s
“That’s also what 
items
 is getting…” Are you referring to this or what? I lost you there a bit 😄
g
Correct
👍 1
s
Everything feels weird, until it doesn’t 😅 That’s my way of thinking about this 😄
true story 1
g
I think this is the point where I leave the honeymoon phase with Compose and reality starts to hit 😂
Are there any resources to learn more about things like that? I plan on getting https://leanpub.com/composeinternals but wonder if there are other resources you know about?
s
Tbh most of the stuff I’ve learned about compose have been all the codelabs and then linger in this slack channel and read a shit ton of threads. Particularly some people stand out to me like: Ian Lake, Adam Powell, Zach Klippenstein, Andrey Kulikov, Albert Chang, Doris Liu, Alex Vanyo, Jim Sproch (and more that I am forgetting right now for sure). If you just search for stuff written just by them on this channel you’re probably gonna learn much more things than you’d imagine. I think this is how I’ve learned all the more “tricky” stuff about compose. And of course using it for hobby projects and later (luckily) for work and exploring what’s going on. I guess these two things also stand out as far as articles go are Zach, Vinay. And then honestly I’ve been very surprised at how readable a lot of the source code of compose is, so when I am using something, using the IDE to navigate inside the sources has taught me a shit ton as well. That’s all I got as far as “resources” for compose 😄
❤️ 1
🙏 1
g
Yes, the code is definitely a big help. Thanks for all of those people, I’ll check those who I don’t know yet, lots of amazing info is all over the channel that’s for sure 👍
👍 1