```Functions which invoke @Composable functions mu...
# compose
c
Copy code
Functions which invoke @Composable functions must be marked with the @Composable annotation
any workaround to change data (outside Composable) placed inside state?
i
not seen this one, got an example of code causing this?
z
You shouldn't need to be in a
@Composable
context to update either a
@Model
nor a
state {
👍 1
c
Copy code
/* TODO here i got: Functions which invoke @Composable functions must be marked with the @Composable annotation*/
@Composable
private val showDialog = state {
    false
}

@Composable
fun SomeComposable(){
    Button(
        "Sign In",
        onClick =
        /* TODO here i got: Functions which invoke @Composable functions must be marked with the @Composable annotation*/
        {
            showDialog.value = false
        }
    )
}
i
I don't think you need the annotation
@Composable
on that
showDialog
state variable
also can you use property delegate for
showDialog
such as private
val showDialog by state { false }
? not sure if it works in all contexts but it works for inline variables and means you don't need to
showDialog.value = false
can simply use
showDialog = false
👍🏻 1
c
i will try
yes
var showDialog by state { false }
is works, looks like i missed
by
explanation when reading
i
nice 👍
Just checking docs I am not sure we should be using property delegates though 🤔
Copy code
import androidx.compose.state
import androidx.ui.core.Text
import androidx.ui.material.Button

val count = state { 0 }

Text(text = "You clicked ${count.value} times")
Button(text = "Click me", onClick = { count.value++ })
aha my apologies those docs show 3 different approaches, quite cool
👍 1
659 Views