TIL of produceState <https://developer.android.com...
# compose-android
c
TIL of produceState https://developer.android.com/develop/ui/compose/side-effects#producestate Is that something that people use often? Not sure how I missed it for the past 2 years lol
s
If you were gonna make a mutable state and then start populating it from a launched effect. Then you do this instead 😅 Here's an example https://github.com/HedvigInsurance/android/blob/develop/app%2Ffeature%2Ffeature-claim-details%2Fsrc%2Fmain%2Fkotlin%2Fcom%2Fhedvig%2Fandroid%2Ffeature%2Fclaim%2Fdetails%2Fui%2FSubmittedAndClosedColumns.kt#L78-L85 But it's definitely kinda niche.
1
f
you can think of it as the opposite of
snapshotFlow
👀 1
🤔 1
z
isn’t any snapshot state implementation the opposite of snapshotFlow?
s
I use 🫡
j
If I remember correct, LaunchedEffect using produceState. I used produceState for example rendering pdf in compose or any async state.
s
j
Right, Thanks mixed it up 😁
m
I like it for having a “current time” state. Something like
val now = produceState(Instant.now()) { while (true) { delay(333) value = Instant.now() } }
For example for a timestamp text that shows “2 mins ago” and should update itself automatically.