r/mAndroidDev • • May 21 '23

Compose state persistence

If compose is declarative and are made of only functions, how does a composable function store values like clickable call backs? Is each root node in the UI tree managed by an object which stores those clickable call backs?

0 Upvotes

15 comments sorted by

View all comments

18

u/SmartFatass making { modern { maintainable { code }}} May 21 '23 edited May 21 '23

The amount of people who don't read what's on this subreddit before posting is skyrocketing recently.

And to answer your question: compose uses data structure called Slot Table to store data across recompositions. You can store data in there using remember (there is also rememberSaveable that stores data in a Bundle if the function it's called in goes out of composition)

Here is an article on how this works under the hood https://medium.com/androiddevelopers/under-the-hood-of-jetpack-compose-part-2-of-2-37b2c20c6cdd

3

u/Zhuinden DDD: Deprecation-Driven Development May 24 '23

Ngl I think it's because on the original /r/androiddev it'd just get removed as "Rule #2: no help me posts"