https://kotlinlang.org logo
e

elye

01/04/2023, 1:05 PM
Should we store "_mutableStateListOf_" in ViewModel or in the Compose Function? If we have it in the Compose Function, looks like we'll need to create a new list for every modification of it, as explain here https://kotlinlang.slack.com/archives/CJLTWPH7S/p1672831604690449. So tempting to put "_mutableStateListOf"_ in the ViewModel, but feel it is wrong.
z

Zach Klippenstein (he/him) [MOD]

01/04/2023, 9:33 PM
It only makes sense to use
mutableStateListOf
if you are going to be modifying the list directly. If the source of truth of the list is your view model, then the state list should live in the view model, where it can be modified directly. Whether your view model uses a mutable state list or an immutable list exposed via a flow or mutable state, it doesn’t really matter.
66 Views