I am sheer beginner in Jetpack Compose library of Kotlin and I was making a simple UI to practice. I Made a Button and I wanted to display a text in the event of someone clicking on code but I got an error
Button( onClick = {
Text("Hello World!")}{
Text("Click Me")}
error: "@Composable invocations can only happen from the context of a @Composable function"
How do I fix it
I was expecting when someone click on the button it shows Hello world under it.
Try like this
**val textClick = remember{ MutableStateOf("Hellllooooo Wooorld") }
Text(text = "${textClick.value}")
Button( onClick = {
textClick.value = "This text changed when I clicked"
} {
Text("Click Me")
}**
The idea is that I have a Text Composable with the value of the textClick variable and I change only the variable's state when I click