Trying to hoist: ```val radioOptions = listOf("Cal...
# compose
d
Trying to hoist:
Copy code
val radioOptions = listOf("Calls", "Missed", "Friends")
val (selectedOption, onOptionSelected) = remember { mutableStateOf(radioOptions[0]) }
Which is from the Compose RadioButton example. Am familiar with hoisting when there is one parameter, but in this case there is the extra parameter onOptionSelected which is throwing me off. Currently I have the child composable accepting the two parameters like:
Copy code
@Composable
fun QuestionRadioButtons(
    selectedOption: String,
    onOptionSelected: (String) -> (Unit)
) { ... }
k
What’s the question?
d
What is onOptionSelected and how is it saved by mutableStateOf ?
I'm not sure why onOptionSelected is needed when selectedOption already contains the state string.
k
Your UI composable gets
x
as the current state to “display” in the UI, and an
onXSomething
as the lambda to call upwards when the user interacts with that data display, and that interaction should lead to a state change
State update happens outside of your composable, and that place may or may not “accept” the new proposed state
d
Where or how is the onOptionSelected lamba defined?
Thank you!
k
In this particular simplified case, the
onOptionSelected
is a lambda generated for you with no validation, custom acceptance or rejection, persistence or any other part of it you would have in the real app.
👍 1