'Compose not refreshing view on change of mutableStateOf value

I have a ViewModel with the property

var uiState by mutableStateOf(UiState())

I have a composable that accesses this value like so

fun AppView(viewModel: BridgeViewModel) {
    val uiState = viewModel.uiState

    when {
        uiState.isLoading -> {
            LoadingView()
        }
        uiState.data != null -> {
            TextToShareView(to = uiState.data)
        }
    }
}

After the composable is created I trigger a function in my ViewModel that changes the state like so

uiState = UiState(isLoading = true)

The problem is, the composable is not being redrawn when I change the value of state.

Any idea? I can't see how this is different to the official sample in the docs.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source