What's the recommended way to manage a bunch of fi...
# compose
d
What's the recommended way to manage a bunch of filter chips if I need to report their state back to the viewModel? Can I just pass down the
MutableState
from the viewmodel straight and let it be modified/observed in the chip, or should I pass a callback and, say, a Boolean for each one?
e
You don’t “report their state back to the viewModel”, their state should be driven by the viewModel. You can expose a callback however from the VM that will update the state inside of the VM (which will then reflect in the Chip)
d
For each one have a callback + a State?
It gets a bit messy on the vm side...
e
Thats up to you, you can keep one state eg List<Boolean> and one lambda that takes index onChecked { index -> … } Or you could put it in a Map appropriate keys Or you can have them all separate state
d
Ok, thanks! So I guess it's never really good to pass down a MutableState just to avoid all those callbacks then... I really thought that in this case that it's really more Ui code, and that the vm only really cares about the current state of all those filters -- not who or what sets them...
e
Its good to also pass a mutable state but its a little weir and i dont recommend.