In jetpack compose,
We can convert MutableStateFlow<T>
to State<T>
using collectAsState()
and with delegation by
can directly assign T
to the variable.
Now as I understand, it doesn't matter much if I used MutableState<T>
or MutableStateFlow<T>
to hold the state, performance-wise.
But for List types however, it seems there is no special version of Flow, ie, if you really need, you can Flow<List<T>
, which I've seen used most of the time. Then, if you apply collectAsState()
on Flow<List<T>
, you get State<List<T>
.
Now, if I understand correctly, even if a single value was changed (added, removed, modified) in the list the whole list state would be considered new thus all respective list item UI components would be recomposed. While with SnapshotStateList<T>
, only the respective element UI will be (re)composed. Or, Jetpack compose has some internal optimization for State<List<T>
that prevents these types of useless recomposition and I should not worry about it.