Djuro
02/27/2024, 2:32 PMradioButtonNameList: List<String>
and selectedRadioButtonIndex: Int
of course
How do you manage this state. What is clear to me is that radioButtonNameList
will be provided by viewModel
or any other state holder. But is selectedRadioButtonIndex: Int
managed inside the state holder or inside the composable function.
1. Inside the composable
a. Advantage
i. this is nice as it is self managed
b. Disadvantage
i. Imagine the state holder for whatever reason needing to know about the selected item in the future. It can be of course informed when it is changed but it might also need it for some other operation
2. Inside the state holder
a. Disadvantage
i. property drilling
ii. more logic contained inside the state holder making it more difficult to manager
b. Advantage
i. everything is at one place
Do you have some elegant solutions for such scenarios? I was also checkiout out Molecule but am unsure if this is the right use case for it (thought it might be since I have the whole form which is pretty dynamic, has several radio button menus, filtering, dropdowns etc.)Djuro
02/27/2024, 2:35 PMselectedIndex
inside the composable since it is okay for my current usecase, I am still interested about your opinions on this topic thoughStylianos Gakis
02/27/2024, 4:34 PMDjuro
02/27/2024, 5:18 PMStylianos Gakis
02/27/2024, 5:31 PMradio button form makes no sense without having a callback for selected indexYou could say the same about TextField and it’s current
text
onTextChange
pattern, but you’d be surprised to see that the new BasicTextField2 is in fact working without a callback which informs you about the state change. It simply changes the state directly which is stored in MutableState inside the state object.
The same can apply in the radio button form.
Still not sure what property drilling has to do with this, if anything having it all in one state object instead of having the state object that you need to pass down and having a callback on state changes would in fact be less things passed down.Zach Klippenstein (he/him) [MOD]
02/28/2024, 3:59 AMDjuro
02/28/2024, 10:42 AMBasicTextField2
. I kinda changed my opinion a bit now that I went through 3 articles by Alejandra Stamato on medium. I will probably move these into the state holder