Skip to content

Commit 67a2437

Browse files
MelvinBotmkhutornyi
andcommitted
Fix React Compiler compliance: replace ref-during-render with state
Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
1 parent ce77524 commit 67a2437

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/components/Search/SearchMultipleSelectionPicker.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useRef, useState} from 'react';
1+
import React, {useEffect, useState} from 'react';
22
import MultiSelectListItem from '@components/SelectionList/ListItem/MultiSelectListItem';
33
import SelectionListWithSections from '@components/SelectionList/SelectionListWithSections';
44
import useDebouncedState from '@hooks/useDebouncedState';
@@ -49,12 +49,11 @@ function SearchMultipleSelectionPicker<T extends string | string[]>({
4949

5050
// Clear after first render to prevent FlashList from auto-scrolling when data changes
5151
// cause the key to transition from "not found" to "found" (e.g., clearing a search).
52-
const initialFocusAppliedRef = useRef(false);
52+
const [initiallyFocusedKey, setInitiallyFocusedKey] = useState(initiallyFocusedKeyComputed);
5353
useEffect(() => {
54-
initialFocusAppliedRef.current = true;
54+
// eslint-disable-next-line react-hooks/set-state-in-effect -- One-time clear after mount; prevents FlashList auto-scrolling when data changes cause the key to re-match
55+
setInitiallyFocusedKey(undefined);
5556
}, []);
56-
// eslint-disable-next-line react-hooks/refs -- Reading ref to detect post-mount state; intentional one-time prop pattern
57-
const initiallyFocusedKey = initialFocusAppliedRef.current ? undefined : initiallyFocusedKeyComputed;
5857

5958
const searchLower = debouncedSearchTerm.toLowerCase();
6059
const sectionData: Array<{text: string; keyForList: string; isSelected: boolean; value: T; leftElement?: React.ReactNode}> = [];

0 commit comments

Comments
 (0)