Lance Gao
02/18/2022, 6:27 AMrember { mutableStateOf(mutableListOf<Int>())}
?mattinger
02/18/2022, 6:43 AMval state = remember { mutableStateOf(listOf<Int>()) }
state.value = state.value + 1
This creates a new list with the additional element appended to the end of it and reassigns the value in the state. This allows the observers (ie, the recomposer) to know that the value changed and things need recomposing.
However, if you do this:
state.value.add(1)
You are simply changing the data inside the list, which no one is observing. There's no way for the recomposer to know that anything changed.MutableState<List<Int>>
and not MutableState<MutableList<Int>>
Lance Gao
02/18/2022, 6:48 AMstate
a new list to notify the recomposer right?mattinger
02/18/2022, 6:48 AMLance Gao
02/18/2022, 6:48 AMmattinger
02/18/2022, 7:13 AMLance Gao
02/18/2022, 7:41 AMColton Idle
02/18/2022, 8:43 AM