Mjahangiry75
02/18/2022, 2:26 PMSideEffect gets triggered on every recomposition
so it works fine in the code below(triggered only once when MainScreen starts composition), but if I uncomment the LaunchedEffect the SideEffect block will get triggered whenever the count state changes, while if I comment the LaunchedEffect block it will not. why?Alexander Maryanovsky
02/18/2022, 2:38 PMcount access when calling LaunchedEffectMjahangiry75
02/18/2022, 2:42 PMLaunchedEffect has access but SideEffect doesn't, how does LaunchedEffect affect SideEffect?Adam Powell
02/18/2022, 2:58 PMval count = remember { mutableStateOf(0) }
SideEffect { ... }
val currentCount = count.value // accessing count's value invalidates MainScreen
LaunchedEffect(currentCount) { ... }
MainScreen is reading count and listening for invalidations of it in order to obtain the value to pass as the LaunchedEffect keyAdam Powell
02/18/2022, 2:59 PMcount read, then MainScreen no longer invalidates when count changes. It has no reason to.Zoltan Demant
02/18/2022, 2:59 PMAdam Powell
02/18/2022, 3:00 PMBox. You can't just count the {} nesting 🙂Adam Powell
02/18/2022, 3:01 PMColton Idle
02/18/2022, 5:07 PMSideEffect gets triggered on every recomposition" is that true or is it better/more accurate to say "gets triggered at the end of every successful recomposition"?Stylianos Gakis
02/18/2022, 6:08 PMAdam Powell
02/18/2022, 6:17 PMSideEffect function executes on every recomposition of the recompose scope it appears in, scheduling the provided function parameter to execute after the changes from the composition are successfully applied and RememberObservers have run"