Which is the difference betwen ```val stateHolder ...
# compose
p
Which is the difference betwen
Copy code
val stateHolder = remember { MyState() }
and
Copy code
val stateHolder by remember { mutableStateOf(MyState()) }
Checking nowinandroid sample, they use a NiaAppState that they declare using the first way, without mutableStateOf. Supposedly, mutableStateOf is necessary to listen to changes in variables, so, why not using it?
For example, in this case, which approach is necessary and why?
Copy code
@Stable
class MyState{
    var currentStep by mutableStateOf(Step.ARE_YOU_SATISFIED)
        private set

    fun updateCurrentStep(value: Step) {
        currentStep = value
    }
}
maybe it's because currentStep is already a mutableStateOf? and the value of MyState is not changed but the value of it's internal variable does?
a
They did a wrapper
Around mutablestate
s
Yeah having two "layers" of mutability is not what you want basically ever. This article https://blog.zachklipp.com/two-mutables-dont-make-a-right/ isn't focused on exactly this I think, but it may still be useful for you to read.
☝️ 1