https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
c

Christopher Porto

07/31/2022, 7:00 AM
I have an object wrapped in
mutableStateOf
and inside the object I have string property. Im trying to use that string property for
TextField
but when I type in it, it doesn't change the text value in UI. Whats the proper way of doing this? Thanks In parent class I have
Copy code
var config by mutableStateOf(SomeConfig(""))
and then I call it like this
Copy code
TextField(config.token, onValueChange = {
            config.token = it
        })
r

Ruckus

07/31/2022, 3:04 PM
Either
SomeConfig
needs to be immutable, or it shouldn't be a state while
token
should be.
l

Landry Norris

08/01/2022, 2:01 PM
config = config.copy(token = it)
assuming SomeConfig is a data class
a

Abdelilah El Aissaoui

08/02/2022, 5:16 PM
Remember to also wrap your mutable state in a
remember {}
block
c

Christopher Porto

08/10/2022, 7:23 PM
@Ruckus That is what I ended up doing (making the properties of
SomeConfig
a mutable state one by one), I was just under the assumption that wrapping the object itself will automatically apply to any changes for its properties
2 Views