https://kotlinlang.org logo
p

PHondogo

07/16/2023, 2:32 AM
Hello! What is the difference between SideEffect and just inlined code in recomposition?
e

ephemient

07/16/2023, 2:50 AM
https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#SideEffect(kotlin.Function0)
Schedule
effect
to run when the current composition completes successfully and applies changes.
code inlined in a composable may be skipped or may be run before the composition completes (which is not always successful, e.g. if another recomposition starts and cancels another one currently in progress)
s

shikasd

07/16/2023, 3:26 PM
right now, the difference is minimal, and mostly related to ordering, as side effects are executed after composition in the future, it might be a bit more important, as we have plans about composition threading/scheduling that might change where composition code and effect code is executed. As a rule of thumb, you want everything that interacts with external systems (and everything that you want to be on the main thread) to be wrapped in effect. they can also be skipped btw, if the content is skipped as well.