This message was deleted.
# compose
s
This message was deleted.
s
It says "captured and updated" which part of this makes you think it will be the same for the rest of the lifetime?
LaunchedEffect would have to have the onTimeout as a key so that if it changed it'd know about it. But doing so would restart the effect and then also restart the delay function there. That's why this technique is used here. Composables do run again when their input has changed as you say, yes. But a LaunchedEffect only reruns when the keys passed to it changes.
Kinda like that yes, but not the exactly same because you're remembering an object which holds a var which is not backed by mutable state. Look inside the implementation of rememberUpdatedState and you'll see how the two differ. Having it be mutableState also means that it then works with if you are reading that updated state in composition or if you pass it down to some other composable
Yeap that's the entire implementation 😅
e
My advice is to always read the code tbh
💯 1
c
The reason
rememberUpdatedState()
exists at all it is a pattern that you can subtly get wrong. The things it does is important. 1) It remembers the
mutableStateOf()
2) the state object it returns is always the same state object, 3) the state is always updated with parameter value passed in. These appear obvious but we saw wrong versions of this often enough to create a helper.