I have a `ModelList` of objects (like a `Story` ob...
# compose
a
I have a
ModelList
of objects (like a
Story
object with a title and body). When updating an object in my
ModelList
, my UI doesn't change. However, if I add an element to the list, or just re-assign the entire list after changes, then the UI updates. Is this behavior expected? What is the best way to manage changing objects within a list that are represented on a Jetpack Compose UI, like in a VerticalScroller or LazyColumnItems so that it actually updates?
a
The mutable object needs to back its mutable properties by
mutableStateOf
if you would like compose to see those changes
Other options include keeping the story object immutable and updating the list with a new changed copy
a
Cool, the latter is what I've tried so far, I'll test out
mutableStateOf
a
If you're doing
myModelList[index] = object.copy(one = 1)
and that isn't causing recomposition, please file a bug as it should be seen as a structural change
👍 1
a
Just to close the loop, I was only updating a property on my object. Using
copy
to change an object at a list index did work to update the UI, thanks for the help.