Thomas
07/08/2024, 3:06 AMState<List<T>>
to SnapshotStateList<T>
?
The best I could come up with is this, but it feels stupid, I wonder if there is a better way.
val a: State<List<T>> = viewModel.collectAsStateWithLifecycle(initialValue = emptyList())
val b: SnapshotStateList<T> by remember{
derivedStateOf {
mutableStateListOf<T>().apply {
addAll(a.value)
}
}
}
(note that when the original State<List<T>>
updates, the SnapshotStateList<T>
should also update)