Asking for Google Keywords :smile: So in my app I ...
# compose-desktop
x
Asking for Google Keywords 😄 So in my app I have a table that is filled by a given
List<String>
. However I'd like to manipulate that state from another
@Composable
function (a popup dialog that opens). The values added in the popup should be added to the
List<String>
of the mentioned table so the content is updated there immediatly. I have a hard time grasping the concepts of state in Compose for Desktop. I am coming from a Vue.js background and I could not build the bridge regarding understanding the way to do that in Compose for Desktop. Therefore I'd like to ask for some keywords I should look out for on Google. I already tried a lib called
Decompose
but I do not fully understand it as it seems to only care about state within a component and not appwide (from my understanding)
a
The Decompose lib is more about navigation and scoping. The state management is beyond its responsibility. As always you can just use MutableState and add values there. Observing children will be updated automatically.
A simple Counter sample could be:
Copy code
@Composable
fun Counter() {
    val state = remember { mutableStateOf(0) }

    Button(onClick = { state.value += 1 }) {
        Text(text = "Count: ${state.value}")
    }
}
Same way you can define your List and add items there.
x
Ok I see. So I have to define that mutable state as "high" in the hierarchy as possible and pass it down to every component that might read/mutate it, right? However I was more looking for a AppWide State management. Is there something like that?
a
You can define you app state at the very top level and pass it down to all Composable functions. You can also check this codelab.
1
x
Sorry @Arkadii Ivanov I looked at the wrong place then with the lib 😄
👍 1