zsperske
08/02/2021, 7:24 PMdata class
which represents my UI state contains a var
and that var changes?
data class EventListState(val events: List<EventUiModel> = emptyList(),
var eventDestination: String = "", //Changes to this var do not cause recomposition
val pastEventsSelected: Boolean = false,
val isLoading: Boolean = true)
zsperske
08/02/2021, 7:25 PMfun updateEventDestination(destination: String) {
val currentState = mutableStateFlow.value
mutableStateFlow.value = currentState.copy(eventDestination = destination)
}
CLOVIS
08/02/2021, 7:28 PMState
class.zsperske
08/02/2021, 7:30 PMZach Klippenstein (he/him) [MOD]
08/02/2021, 7:32 PMzsperske
08/02/2021, 7:33 PMvar
to a val
, then things work as expectedCLOVIS
08/02/2021, 7:35 PMvar
, you are editing the object directly. Compose cannot know that.
If you use a val
, you can't edit the object, so you edit its reference: if that reference is handled by an object Compose understands (State, StateFlow...) then Compose knows about itzsperske
08/02/2021, 7:43 PM