You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have a data class and manage it in state as an basic parameter.
data class Test(var name: String = "")
main = application {
val test = Test("old")
var x by remember { mutableStateOf(test.name) }
Window {
...
}
}
and when I change property of the class object test.name = "new" ui doesn't update cos x waiting for new class object to be set.
I found just a four ways to trigger UI update.
Manage states as an property of data class but thats bad idea and serialization lib doesn't work with it
Create a boolean state variable and change it when you set a new value to property. But thats a useless variable and additional parameter that is need to be set in all ui functions through the hierarchy tree.
Separate data and ui by creating another state, setting it through the hierarchy tree and change state for the new value when data is changing like:
test.name = "new value"
stateVariable = "new value"
But again if there a complex data class with many fields is it worth to create a big number of state variables for each and also set them all to function as an additional parameters? Actually there can be a list with states what decrease number of additional function parameters to one.
Set a state policy = neverEqualPolicy(). But there must be set a new class object anyway.
So what is the right way to update UI on class.property change?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
If I have a data class and manage it in state as an basic parameter.
and when I change property of the class object
test.name = "new"
ui doesn't update cosx
waiting for new class object to be set.I found just a four ways to trigger UI update.
But again if there a complex data class with many fields is it worth to create a big number of state variables for each and also set them all to function as an additional parameters? Actually there can be a list with states what decrease number of additional function parameters to one.
policy = neverEqualPolicy()
. But there must be set a new class object anyway.So what is the right way to update UI on class.property change?
Beta Was this translation helpful? Give feedback.
All reactions