https://kotlinlang.org logo
#compose
Title
# compose
t

Tlaster

08/03/2022, 7:34 AM
About state hoisting, I have two questions: • When we build a simple screen, there will be a few states and few
onValueChange
, but when we build a complex screen, we will get a lot of states and lots of
onValueChange
, there will be many parameters for the composable method, is there any optimization we can do to reduce the parameters? • If we have
onValueChange
inside a very deep composable, it will pass all the way up to the top screen to actually handle the
onValueChange
, is there a better way to do it instead of passing it all the way up to the top screen?
f

Filip Wiesner

08/03/2022, 7:56 AM
1. Try building state objects like
TextFieldValue
which groups several
onChange
candidates together (in this case
text
,
selection
and
composition
) but this one is hard to answer without context. 2. This problem can be partly solved by using the "slot pattern" so you don't pass the lambda down the tree through parameters. Leland Richardson talks about it in his "Thinking in Compose" video (somewhere around 9:30 mark)
t

Tlaster

08/03/2022, 9:59 AM
Thanks! I might need to rethink how to construct Compose application.
7 Views