Hi all, I have this confusion and I hope you guys ...
# compose-desktop
x
Hi all, I have this confusion and I hope you guys can help me clear it up. It is about when/where to use MutableState. Should I wrap my data class in a MutableState, or wrap each of its properties in MutableState? Say I have a hierachy of state classes like this:
Copy code
Class0
        Class0.1
            Class0.1.1
            Class0.1.2
        Class0.2
            Class0.2.1
            Class0.2.2
        Class0.3
            Class0.3.1
            Class0.3.2
Each and every one of them is the state of one or more composables. Given the fact that re-composition happens when MutableStates' values are updated, does it make sense to wrap every properties at all level in a MutableState? Thank you
👍 1
a
Should I wrap my data class in a MutableState, or wrap each of its properties in MutableState.
It depends, everything that changes and need redrawing should be in MutableState. So everything that is mutable and should redraw when changed should be in a MutableState. A class instance inside MutableState can be immutable so you have to change the entire object when you make a copy, or you can put a MutableState for mutable properties.
An example of class with a MutableState property inside of LazyListState, because the scroll state is an changes a lot but it should keep the same object to make it available to the developer.
a
x
@adte Sorry for the late reply, thank you for the answer 😄 @Albert Chang enlightening, thank you.