Skip to content

Commit a2623f2

Browse files
amcaplanclaude
andcommitted
Fix ESLint exhaustive-deps warning in AutocompletePrompt
- Use refs to track current values of choices and initialHasMorePages - Add setPromptState to dependency array (stable React setState function) - Avoids stale closures without breaking throttle functionality - No ESLint disable needed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b0bf803 commit a2623f2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/cli-kit/src/private/node/ui/components/AutocompletePrompt.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ function AutocompletePrompt<T>({
8484
const searchTermRef = useRef('')
8585
searchTermRef.current = searchTerm
8686

87+
// Keep current values in refs to avoid stale closures
88+
const choicesRef = useRef(choices)
89+
choicesRef.current = choices
90+
const initialHasPagesRef = useRef(initialHasMorePages)
91+
initialHasPagesRef.current = initialHasMorePages
92+
8793
// useMemo ensures debounceSearch is not recreated on every render
8894
const debounceSearch = React.useMemo(
8995
() =>
@@ -98,8 +104,8 @@ function AutocompletePrompt<T>({
98104
// has emptied the search term, so we want to show the default
99105
// choices instead
100106
if (searchTermRef.current.length === 0) {
101-
setSearchResults(choices)
102-
setHasMorePages(initialHasMorePages)
107+
setSearchResults(choicesRef.current)
108+
setHasMorePages(initialHasPagesRef.current)
103109
} else {
104110
setSearchResults(result.data)
105111
setHasMorePages(result.meta?.hasNextPage ?? false)
@@ -117,7 +123,7 @@ function AutocompletePrompt<T>({
117123
400,
118124
{leading: true, trailing: true},
119125
),
120-
[paginatedSearch],
126+
[paginatedSearch, setPromptState],
121127
)
122128

123129
return (

0 commit comments

Comments
 (0)