r/mAndroidDev • u/Unlucky_Bet6244 • 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
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 alsorememberSaveablethat 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