I am learning Jetpack Compose but facing some issues in understanding states. Can someone explain these two? observeAsState and collectAsState. Thank you.
observeAsState
is an extension on LiveData
.
Starts observing this LiveData
and represents its values via State
.
Uses Lifecyle
internally for safely observing the data.
collectAsState
is an extension on StateFlow
.
Collects values from this StateFlow
and represents its latest value via State.
You need to handle the collection as per appropriate Lifecyle
.
Source: Compose#LiveData & Compose#Flow.