Skip to content

Commit

Permalink
ensure array vs string in addCustomOptionIfNeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklloyd committed Apr 11, 2024
1 parent f59bed3 commit aa3c822
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/SearchSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ const SearchSelect = ({
updatedValues: OptionType | OptionType[] | undefined,
value: string | string[] | readonly string[] | undefined
): OptionType | OptionType[] | undefined => {
if (!value || !updatedValues || !Array.isArray(updatedValues))
return updatedValues;
if (!value || !updatedValues) return updatedValues;

return typeof value === 'string'
? findOrCreateOption(value)
: value.map((v) => findOrCreateOption(v));
if (Array.isArray(value)) {
return value.map((v) => findOrCreateOption(v));
} else if (typeof value === 'string') {
return findOrCreateOption(value);
} else {
return updatedValues;
}
};

useEffect(() => {
Expand Down

0 comments on commit aa3c822

Please sign in to comment.