Ayomide01/30/2021, 2:50 PM
composables that are created as "children" of a
composable. Which means I have to hoist the same
callback to all of them. But how would I get a name like
function that is given to all the buttons in the image when the
button is clicked? I feel like I am modelling this wrong, since composables should largely be stateless, except for the top level composable
jim01/30/2021, 3:45 PM
Which means I have to hoist the sameThis is the sentence which doesn't sound right to me. It's totally ok to have a different lambda for each child, you don't need to hoist the lambda creation up. Thecallback to all of them.
lambda is not composable and so almost by definition it is stateless. When we say "stateless" we generally mean "no direct or indirect calls to `remember`". We mean that if you were to rerun/recreate the composable, or reuse the old composable, you wouldn't be able to tell the difference. An
lambda is not Composable and so it is almost by definition not going to be stateful because
can only be called from a composable function. Recreating a non-stateful lambda on every composition is totally ok (and Compose may even do some optimizations to avoid unnecessary allocations, but you can safely ignore that detail). Therefore you don't need to worry about hoisting the `onClick`s up. Does the above make sense? I know, the data flow of functional composables can be a bit mind-bending the first time you see it, since it's so different from how data flow worked with the old Android View system and other imperative UI systems. Feel free to post some code snippets if you're still confused and we can help you refactor them.
Ayomide01/30/2021, 4:02 PM
that needed the text of whatever button was clicked to fetch that file. Made much more sense than hoisting one onClick
for all of the buttons!