How do we do real time updates with jetpack compos...
# compose
m
How do we do real time updates with jetpack compose? Example updating stock price of list of stocks in a list. Do we need to convert list to mutable list and change price each time we get a new price or is there any other ? Thanks in advance
j
Whenever you have a State, compose will update the view automatically if the state changes. How the state is changed is determined by your app, e.g. it could be a Flow/LiveData fetched from the Database or a pull-based update. If you periodically pull new data from an API, then yes, you could use a MutableState / MutableStateFlow and modify it when there's a new value. A mutable list alone won't help, as compose doesn't automatically monitor lists for changes. Only states.
z
Yep, you can do this one of two ways: 1. Send new immutable list values, where you get a whole new list each time. The immutable list gets stored in a mutable state. 2. Directly manipulate a mutableStateListOf. Some more discussion on that here.