I've seen this pattern cropping up in some compose...
# compose
c
I've seen this pattern cropping up in some compose repos from others... thoughts? At first glance I guess it's kinda clever for trying to get something to launch only once, but it just seems bad
Copy code
LaunchedEffect(key1 = "launch_once") {
    myViewModel.doSomething()
  }
s
At first glance I guess it's kinda clever for trying to get something to launch only once
It's basically
LaunchedEffect(Unit)
, isn't it?
☝🏼 1
☝️ 2
☝🏽 1
3
a
Any constant will do but
Unit
is more or less what we standardized on.
true
had some support on the team for a while
LaunchedEffect(Unit)
is meant to look suspicious in the same way
while (true)
looks suspicious. The lack of a "real" key there is supposed to invite closer reading
2
we've had some discussion around whether this has been effective or if it's just kinda noisy. The discussion it invites I think is sort of anecdata suggesting some positive results
and in the case of the example that started the thread, the key should probably be
myViewModel
🙂
👍 1