updateState
Updates the UI state synchronously without showing loading indicators or handling errors.
Use this function for immediate, synchronous state updates such as:
Text input changes
UI toggle states
Local UI state modifications
Navigation state updates
This function does NOT:
Set loading state
Handle exceptions
Run in a coroutine scope
Usage Example
@HiltViewModel
class ProfileViewModel @Inject constructor() : ViewModel() {
private val _uiState = MutableStateFlow(UiState(ProfileScreenData()))
val uiState = _uiState.asStateFlow()
fun updateName(name: String) {
_uiState.updateState {
copy(name = name)
}
}
}Content copied to clipboard
Parameters
update
Lambda that receives current data and returns updated data. Use data class copy() to create the new state.
Type Parameters
T
The type of the screen data.
See also
for async operations that return new data
for async operations that return Unit