One thing I don't get with CompositionLocals is th...
# compose
c
One thing I don't get with CompositionLocals is that I need to "get" my local outside of my composable. i.e. Why do I have to do this?
Copy code
val backHandler = LocalOnBackPressedDispatcherOwner.current
MyButton(
    clickEvent = { backHandler?.onBackPressedDispatcher?.onBackPressed() },
instead of this
Copy code
MyButton(
    clickEvent = { LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher?.onBackPressed() },
r
It's the opposite. Your click event lambda is not a composable and therefore doesn't have access to the composition local. You are accessing the composition local from a composable in your example
👍🏻 1
c
ah. okay. visually it looks like im in my composable, but im not actually. it was all an illusion. cheers
s
Random trivia: If clickEvent was an inline function this would be possible since it’d consider itself to be inside the scope of your composable function