s3rius
11/05/2023, 3:35 PMclass State {
var item by mutableStateOf<IClass?>(null)
}
@Composable
fun SomeUi(state: State) {
Text("Item is ${state.item}")
}
SomeUi()
is rendered to screen, and state.item
is changed from null
to some value a little afterwards. But SomeUi
never picks up on that update and thus the text keeps saying "Item is null"
. But the way I understand the Compose state system, this should work fine, shouldn't it?
I can verify that state.item
does change its value (by just periodically printing it in a coroutine). What's odd is that if I experimentally change IClass?
to String?
it works again.
I want to put more effort into debugging it, but first I'd like to verify that I'm not simply misunderstanding something about State and how it's supposed to work.Rafs
11/05/2023, 3:51 PMSomeUI
from?s3rius
11/05/2023, 3:54 PMapplication {
val state = remember { State() }
LaunchedEffect(Unit) { // just an example
delay(100)
state.item = getMeSomeItem()
}
SomeUi(state)
}
The real code is much more involved, but conceptually it's this.
Edit: added the remember { }
Rafs
11/05/2023, 3:55 PMval state = remember{ State() }
s3rius
11/05/2023, 3:55 PMRafs
11/05/2023, 3:59 PMs3rius
11/05/2023, 4:05 PMstate
or item
, or something else.
For example if someone had told me "Yeah your State needs to be @Stable for this to work" I could have stopped debugging the problem. But if the answer is "No, this should always work" then I have to do more in-depth debugging to pin point the reason why it doesn't work in this case.s3rius
11/05/2023, 4:07 PMZach Klippenstein (he/him) [MOD]
11/06/2023, 4:57 PM