Why is `LaunchedEffect` called multiple times? ``...
# compose
c
Why is
LaunchedEffect
called multiple times?
Copy code
var isInitialized by remember { mutableStateOf(false) }
Log.d("aos","CompleteRoute")

LaunchedEffect(Unit) {
    if(isInitialized) return@LaunchedEffect
    isInitialized = true

    Log.d("aos","LaunchedEffect")
}
d
Because the surrounding composable is called multiple times?
b
It should not be launched once when entering in the composition ? (I mean not at each recomposition)
d
It is launched once per call
s
It should not be launched once when entering in the composition ? (I mean not at each recomposition)
This is still true though. "Once per call" I assume here puts the emphasis that if you call the composable from multiple places then yes it will be called once per each call site. Other than that it shouldn't run multiple times, how do you call it which makes it trigger multiple times as you say? Is it perhaps part of an if/else statement where it enters and exits composition multiple times?
619 Views