https://kotlinlang.org logo
e

Eric Womer

10/09/2022, 2:13 PM
How do I call a @Composable function from within LiveData's observe method?
a

Adam Powell

10/09/2022, 3:01 PM
You don't; a LiveData observer is an imperative event callback and a
@Composable
function is declarative. LiveData observers are about applying changes when data changes occur, but a Compose composition is already an engine for doing this. Check out the
LiveData.observeAsState
extension function; you can call it from inside of a
@Composable
instead of manually adding observers to the LiveData.
e

Eric Womer

10/09/2022, 4:08 PM
Is there anywhere else to look up api references, developer.android.com is taking forever with its searches
a

Adam Powell

10/09/2022, 4:16 PM
that's the source of truth for the docs. Where are you searching from? curious what might be going on if search there is taking a while
e

Eric Womer

10/09/2022, 4:19 PM
Top of the page, tried looking manually in the api reference page and couldn't find it. Found this article though https://luboganev.dev/post/observe-as-state-is-the-new-postvalue/
a

Adam Powell

10/09/2022, 4:22 PM
The search at the top of the page shows me this for the search query observeAsState:
are you seeing something different?
e

Eric Womer

10/09/2022, 4:24 PM
I'm seeing it just spinning
a

Adam Powell

10/09/2022, 4:25 PM
hm, interesting. Any extensions? It comes back pretty quick for me using chrome or firefox, uBlock origin, privacy badger active
(curious if there's anything interesting to report to our docs team here)
e

Eric Womer

10/09/2022, 4:30 PM
The only shared extension between (its Firefox browser) the browers on my phone and desktop is uBlock
It maybe because I live behind a vpn constantly?
Now its instant
5 Views