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

myanmarking

01/19/2022, 12:44 PM
LaunchedEffect can see ‘updated’ State objects, but not non-state variables right? That why we use rememberUpdatedState. Can some1 explain this better to me please
f

Filip Wiesner

01/19/2022, 12:51 PM
Correct me if I'm wrong but that's not "compose specific" question, right? If you capture value in lambda, than you will see the captured value. If you capture object like state, you will see the same object but it's value has changed so you will see the new value.
☝🏻 1
✔️ 2
z

Zach Klippenstein (he/him) [MOD]

01/19/2022, 1:29 PM
Filip is correct, this fundamentally has nothing to do with compose. But in addition, you also don’t need
State
objects for lambdas to see updates. If you’re updating properties on an object captured by a lambda, that lambda will see the updated properties of the object when it asks for them. That said, if you’re writing the state updates from a composition, you should definitely be using snapshot state objects – not because
LaunchedEffect
, or lambda capture in general, requires them, but because updating non-snapshot-state objects from a composition is considered a “side effect” in the general sense, and has all the same issues as performing any side effect from a composition (e.g. side effects from discarded compositions look like they come from nowhere).
2 Views