Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Created May 11, 2021 11:18
Show Gist options
  • Save JoseAlcerreca/4f8d69ef0e8225b4a067d5f42ee95303 to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/4f8d69ef0e8225b4a067d5f42ee95303 to your computer and use it in GitHub Desktop.
class MyViewModel {
private val _myUiState = MutableStateFlow<Result<UiState>>(Result.Loading)
val myUiState: StateFlow<Result<UiState>> = _myUiState
// Load data from a suspend fun and mutate state
init {
viewModelScope.launch {
val result = ...
_myUiState.value = result
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment