Skip to content

Commit 7c662c0

Browse files
MelvinBotmkhutornyi
andcommitted
Inline initiallyFocusedKeyComputed into initiallyFocusedKey useState initializer
Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
1 parent 47fdb69 commit 7c662c0

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/components/Search/SearchMultipleSelectionPicker.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ function SearchMultipleSelectionPicker<T extends string | string[]>({
3535

3636
const [initialSelectedIDs] = useState(() => new Set((initiallySelectedItems ?? []).map((item) => item.value.toString())));
3737
const [selectedItemIDs, setSelectedItemIDs] = useState(() => initialSelectedIDs);
38-
const [initiallyFocusedKeyComputed] = useState(() => {
38+
// Clear after mount to prevent FlashList from auto-scrolling when data changes
39+
// cause the key to transition from "not found" to "found" (e.g., clearing a search).
40+
// Deferred by one frame so FlashList processes the initial scroll first.
41+
const [initiallyFocusedKey, setInitiallyFocusedKey] = useState(() => {
3942
let minItem: SearchMultipleSelectionPickerItem<T> | undefined;
4043
for (const item of items) {
4144
if (initialSelectedIDs.has(item.value.toString())) {
@@ -46,11 +49,6 @@ function SearchMultipleSelectionPicker<T extends string | string[]>({
4649
}
4750
return minItem?.name;
4851
});
49-
50-
// Clear after mount to prevent FlashList from auto-scrolling when data changes
51-
// cause the key to transition from "not found" to "found" (e.g., clearing a search).
52-
// Deferred by one frame so FlashList processes the initial scroll first.
53-
const [initiallyFocusedKey, setInitiallyFocusedKey] = useState(initiallyFocusedKeyComputed);
5452
useEffect(() => {
5553
const id = requestAnimationFrame(() => {
5654
setInitiallyFocusedKey(undefined);

0 commit comments

Comments
 (0)