I have a ViewModel which has the following list as StateFlow
private val _mutableStateTopicItemList = MutableStateFlow<List<TopicItem>>(listOf())
val stateTopicItemList = _mutableStateTopicItemList.asStateFlow()
Now inside my Composable function, I want to get an update whenever there's a change in the value of this above variable stateTopicItemList
TopicItem
is my CustomClass.
I want an observable inside my Composable that observes any changes like add/update/delete from the viewModel List variable stateTopicItemList
I tried to use the collectAsState() method to get an update but was unsure how to listen to those updates. See this what I tried.
val listOfTopicsWithState = myViewModel.stateTopicItemList.collectAsState()
What I want to achieve is just that whenever there's a change in the list, I want to store it inside my SharedPreference.
Any help will be really appreciated.