Peter
08/14/2023, 9:08 AMisSelected
as an additional key?
val selectedIndex by remember {
mutableStateOf(2)
}
for (i in 0 until 4) {
val isSelected = i == selectedIndex
val text = "$isSelected"
key(i) {
Text(text)
}
}
Stylianos Gakis
08/14/2023, 9:12 AMkey
would change if something recomposes more efficiently, I thought it’d only be for correctness,
.
But regarding this example here, why not write it like this
for (i in 0 until 4) {
key(i) {
val isSelected = i == selectedIndex
val text = "$isSelected"
Text(text)
}
}
So that you are sure these 4 separate calls are keyed properly.Peter
08/14/2023, 10:35 AMPeter
08/14/2023, 10:36 AMkey
, to make Text
recompose only if needed. I've tried key(i, isSelected)
etc.Stylianos Gakis
08/14/2023, 10:37 AMText
skip recomposition if the text provided to it is the exact same as it was previously?Stylianos Gakis
08/14/2023, 10:38 AMPeter
08/14/2023, 10:40 AMStylianos Gakis
08/14/2023, 10:43 AMkey
is where you want to go when you want to limit recompositions, extracting composable functions with stable parameters maybe is the way to go if there’s some recomposition scopes that make way too many composables try to recompose themselves.