Skip to content

Commit

Permalink
fix: Prevent mutating value prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Dow committed Apr 30, 2024
1 parent 47bb4d4 commit 362ad34
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/inputs/internal/ComboBoxBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function ComboBoxBase<O, V extends Value>(props: ComboBoxBaseProps<O, V>)
// Though, it is possible that the `options` prop has changed, which is a dependency on this `useMemo`.
// That could trigger an unnecessary new reference for `selectedOptions`, and cause additional renders or unexpected state changes.
// We should avoid updating `selectedOptions` unless `values` has actually changed.
if (!equal(values.sort(), selectedOptionsRef.current.map(getOptionValue).sort())) {
if (!equal([...values].sort(), selectedOptionsRef.current.map(getOptionValue).sort())) {
selectedOptionsRef.current = options.filter((o) => values.includes(getOptionValue(o)));
}

Expand Down

0 comments on commit 362ad34

Please sign in to comment.