Thread
#compose
    jkm

    jkm

    1 year ago
    Hey everyone, quick question regarding state in compose. Say I have a screen full of checkboxes, and I receive a model that details whether or not they should be toggled. i.e.
    data class Model( var one: Boolean, var two: Boolean, //etc)
    do I: A. declare each of the checkboxes states ? i.e.
    var someState by remember { mutableStateOf(myModel.one) }
    B. declare the state of the collection of checkboxes as
    var someState by remember { mutableStateOf(myModel) }
    I would like to do B, but I’m struggling with the state change callbacks, I’m thinking I might have to do A
    Will Shelor

    Will Shelor

    1 year ago
    I think if you want to use the second, you would need to say someState = someState.copy(two = true), or something like that. I believe x by remember will redraw only when the object is directly assigned, not when the states within it are updated.
    jkm

    jkm

    1 year ago
    Thanks! You’re correct, didn’t realise a change to
    State<T>.someProperty
    wouldn’t trigger a recomposition