If I have `val state = remember { ... }` and then ...
# compose
d
If I have
val state = remember { ... }
and then below this line I have
Column { Box { Column { Component(state) } } }
, 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
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
thank you all!
m
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
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