Stylianos Gakis
03/06/2023, 12:20 PMif(x) {
callLambda()
}
and why you need to do this instead
LaunchedEffect(x) {
if(x) {
callLambda()
}
}
In order to avoid calling this lambda again and again if the composable recomposes for other reasons.
Is there some part of the docs which highlights this?
I can’t find any atm 👀Csaba Szugyiczki
03/06/2023, 2:19 PMLaunchedEffect(x)
guarantees that no matter how many times your Composable is run, the block within your LaunchedEffect will run exactly once, and once the value of x changes theCoroutineScope will be cancelled within it.
On the other hand when you only put your if conditional directly inside your Composable, if it is recomposed and x
evaluates to true then callLambda()
will be called on every recomposition.Stylianos Gakis
03/06/2023, 2:19 PMCsaba Szugyiczki
03/06/2023, 2:20 PMStylianos Gakis
03/06/2023, 2:28 PM