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:
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
adte
07/02/2023, 8:49 AM
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.
adte
07/02/2023, 8:54 AM
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.