I've got this code: ``` var connectionFlow: Mut...
# compose
I've got this code:
Copy code
var connectionFlow: MutableStateFlow<GattConnectionState> = MutableStateFlow(GattConnectionState.STATE_DISCONNECTED)
    val bluetoothConnectionState by connectionFlow.collectAsState()
    val isConnected = bluetoothConnectionState == GattConnectionState.STATE_CONNECTED

    LaunchedEffect(address) {
        connectionFlow = viewModel.connect(address)
I think it's not recomposing when I replace
, what's the correct way to implement this?
You are creating a new
on each recomposition with the code you provide here at least. Is that what you want here? Also, it’s not inside a MutableState, so if you change a var like that compose has no reason to recompose at all
Copy code
fun asd() {
  var x = 1
  LaunchedEffect(Unit) { x = x + 1 }
This will of course not trigger a recomposition as a normal var which is not backed by MutableState won’t inform composition that there’s something that has changed and a recomposition needs to happen.
Hmm, I pushed the flow creation onto the ViewModel. Good to know on the recreation.