Skip to content

Commit

Permalink
Wrap OrgUnitSelectorItem in a key (#315)
Browse files Browse the repository at this point in the history
This acts same as item key in lazy views. Prevents the composable from recomposing unnecessarily when the key didn't change in the control flows. Like in this `forLoop` for example.
  • Loading branch information
msasikanth authored Oct 14, 2024
1 parent 668a98d commit 021760f
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -199,13 +200,15 @@ private fun OrgTreeList(
horizontalAlignment = Alignment.Start,
) {
orgTreeItems.forEach { item ->
OrgUnitSelectorItem(
orgTreeItem = item,
higherLevel = orgTreeItems.minBy { it.level }.level,
searchQuery = searchQuery,
onItemClick = onItemClick,
onItemSelected = onItemSelected,
)
key(item.uid) {
OrgUnitSelectorItem(
orgTreeItem = item,
higherLevel = orgTreeItems.minBy { it.level }.level,
searchQuery = searchQuery,
onItemClick = onItemClick,
onItemSelected = onItemSelected,
)
}
}
}
}
Expand Down

0 comments on commit 021760f

Please sign in to comment.