Can we mutate the items list being passed in to th...
# compose
k
Can we mutate the items list being passed in to the
LazyColumnFor
? Like adding or removing items and expect the changes to be reflected in the
LazyColumn
? Something like
adapter.notifyDatasetChanged()
we used to do with
RecyclerView
t
Yes but you need to use:
Copy code
val list: SnapshotStateList<YouDataType> = mutableStateListOf()
When you change this list using add, remove, ... the UI will refresh automatically
k
Okay! So it'll just recompose that single add/remove right? Or it'll recompose the entire
LazyColumn
I'm concerned whether there are any performance hits by doing so?
t
I am not sure how exactly this is implemented in the LazyColumn/LazyRow. But currently this is the only way i am aware of to change the content dynamically without refreshing the complete list.
d
I have used both and
SnapshotStateList
does granular updates,
State<List<...>>
does not.