Hi, I have a composable as follows: ```var isLoadi...
# compose
f
Hi, I have a composable as follows:
Copy code
var isLoading by remember(data) { mutableStateOf(false) }

LaunchedEffect(events) {
    events.collect {
        isLoading = true
    }
}
The idea is that I have a local
isLoading
state that I want to set to true when
events
emits something. I want to reset it to false, when
data
changes. This works perfectly the first time
events
emits.
isLoading
goes to
true
and when updated
data
comes in, it goes back to
false
.
However, the second time
events
emits,
isLoading
stays false.
even though
isLoading = true
is run
I'm struggling to understand whats going on, maybe I'm doing something wrong?
To answer my own question for anyone curious: when
data
changes, a new
mutableStateOf
is created but the
LaunchedEffect
is not keyed on it. Hence what happens when
events
emit is that it changes the previous mutable state which no one is listening to anymore.
The best solution I came up with so far is not to use delegation for
isLoading
and then passing it as a key to the effect.
Would anyone see better options?
e
Another option is to also key launched effect on data