Skip to content

Commit 369599d

Browse files
fix: use useEffect for value prop handling in MultiSelectCombobox
Replaces the problematic reference comparison with proper useEffect to handle controlled value prop updates. This ensures that when the value prop changes, the selected state is properly updated. Co-authored-by: jaaydenh <1858163+jaaydenh@users.noreply.github.com>
1 parent b4516dc commit 369599d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

site/src/components/MultiSelectCombobox/MultiSelectCombobox.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,12 @@ export const MultiSelectCombobox = forwardRef<
223223
const [inputValue, setInputValue] = useState("");
224224
const debouncedSearchTerm = useDebouncedValue(inputValue, delay || 500);
225225

226-
const [previousValue, setPreviousValue] = useState<Option[]>(value || []);
227-
if (value && value !== previousValue) {
228-
setPreviousValue(value);
229-
setSelected(value);
230-
}
226+
// Handle controlled value prop
227+
useEffect(() => {
228+
if (value) {
229+
setSelected(value);
230+
}
231+
}, [value]);
231232

232233
useImperativeHandle(
233234
ref,

0 commit comments

Comments
 (0)