Thomas
12/03/2024, 4:38 AM@Composable
fun F() {
val state = remember { mutableStateOf("Test") }
A(state)
B(state.value)
/* ... */
}
@Composable
fun A(state: State<String>) {
Text(text = state.value)
}
@Composable
fun B(value: String) {
Text(text = value)
}
Can we claim that A
is always better than B
, because when `state`'s value changes B(state.value)
causes F
to recompose, while A(state)
does not cause F
to recompose?
Or does it even matter in practice?Stylianos Gakis
12/03/2024, 9:04 AMfun A(getState: () -> String)
instead of passing the State
around.
Other than that, if you always do it it's just gonna be clunky in the API and in many cases you won't even get any performance benefit from it.
So I'd say do it only when you know you need it, not always.marcinmoskala
12/03/2024, 9:20 AMmarcinmoskala
12/03/2024, 9:21 AM() -> String
would secure and generalize it, so I agree it would be beneficial.Stylianos Gakis
12/03/2024, 9:25 AM