Can anyone suggest strategies for handling `TextF...
# compose
s
Can anyone suggest strategies for handling
TextField
data in a ViewModel that is shared between Compose and non-Compose targets?
When it was Compose-only, I was using
MutableState
. There's no validation done while changing values. I'm thinking to use a
MutableStateFlow
to get the initial values and only pass them back to the VM when submitting the form.
z
You can use the MutableState from compose in non-compose-ui targets without depending on any of compose ui too, if you want.
s
I don't think that I should bring the compose dependency in my JS target. Maybe I can expect/actual my way around this? I've read that collecting the state of
MutableStateFlow
like
.collectAsState(Dispacters.Main.immediate)
should avoid any async issues. Do you know if that's true?
z
That doesn’t prevent you from introducing asynchrony into your flow in other ways. Eg some standard flow operators do this sneakily.
s
Thanks. My usage is really simple. The values are loaded by the VM initially, then only modified by the TextField. Then they're read by the VM when the user hits a submit button.
👍🏻 1