I'm having a problem that the mutable state ignores first value if set two values in a row. I assume it's expected behaviour, just wondering if there is a clean workaround for that? I have this code:
var userState by mutableStateOf<UserData?>(null)
fun clearState() {
userState = null // clear user state
cleanInnerState()
// Set next user state if exist
stateQueue.poll()?.let {
userState = it
}
}
@Composable
fun ProfileScreen() {
val userData = store.userState
if(userData == null){
clearViewModelState()
}
else {
UserUI(userData)
}
}
The problem that when we set the state value to null and then we set new state in a row it ignores the null value and observers the last set value only.