Reputation: 66
I have a Button and I would like to access LocalComponents.current
in its onClick
Button(onClick = {
with(LocalRootComponent) {
current.doStuff()
}
})
but IDE complains with
@Composable invocations can only happen from the context of a @Composable function
Upvotes: 0
Views: 92
Reputation: 16534
You can access and store that object outside the onClick
method, and then use that variable inside onClick
, e.g.:
val rootComponent = LocalRootComponent.current
Button(onClick = {
rootComponent.doStuff()
})
Upvotes: 2