, does it make any difference (performance or memory-wise) to have this state closer to its usage, i.e. should I put it in the innermost lambda rather than have it outside? I mean in this case none of intermediate composable lambdas need this state and this is known to stay like this. But having it "outside" is sometimes better for organizational purposes.
f
Filip Wiesner
07/06/2021, 10:45 AM
If the question was more about performance then AFAIK it shouldn't matter where you put your State. Only composable scopes that read the value will recompose on change and it does not matter how nested they are.
d
dimsuz
07/06/2021, 10:48 AM
thank you all!
m
Manuel Vivo
07/06/2021, 11:31 AM
Using the property delegate in mutable states (i.e.
val state by remember { mutableStateOf(…) })
aims for automatic better performance as that state is only read when it’s actually needed
Manuel Vivo
07/06/2021, 11:32 AM
Even if you get good performance automatically by using the property delegate, moving the definition of the state close to where it’s used is also good for readability