James Ward
11/06/2020, 3:23 PM@Composable
fun MyButton() {
Button(onClick = {
launchInComposition {
delay(10)
}
}) {
Text("hello, world")
}
}
And getting: @Composable invocations can only happen from the context of a @Composable function
@Composable
fun MyButton() {
val scope = remember { CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate) }
onActive { onDispose { scope.cancel() } }
Button(onClick = {
scope.launch {
delay(1000)
println("asdf")
}
}) {
Text("hello, world")
}
}
Grigorii Yurkov
11/06/2020, 4:08 PMrememberCoroutineScope()