Skip to content

Commit

Permalink
fix: add memo to autocomplete options
Browse files Browse the repository at this point in the history
  • Loading branch information
benlister-okta committed Feb 1, 2024
1 parent 6383c3b commit c6c0d5d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/odyssey-react-mui/src/labs/DataFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ const DataFilters = ({
}
}, [onChangeSearch, searchValue, searchDelayTime, hasSearchSubmitButton]);

const autocompleteOptions = useMemo(() => {
// Check if filterPopoverCurrentFilter and filterPopoverCurrentFilter.options are defined
if (
filterPopoverCurrentFilter?.variant === "autocomplete" &&
filterPopoverCurrentFilter?.options
) {
return filterPopoverCurrentFilter.options.map((option) => ({
label: option.label,
}));
}

// if filterPopoverCurrentFilter or filterPopoverCurrentFilter.options is undefined
return [];
}, [filterPopoverCurrentFilter]);

const updateInputValue = useCallback(
({ filterId, value }: { filterId: string; value: DataFilterValue }) => {
setInputValues({ ...inputValues, [filterId]: value });
Expand Down Expand Up @@ -428,11 +443,7 @@ const DataFilters = ({
value: label,
});
}}
options={filterPopoverCurrentFilter.options.map(
(option: { label: string }) => ({
label: option.label,
})
)}
options={autocompleteOptions}
/>
</AutocompleteInnerContainer>
<Button
Expand Down

0 comments on commit c6c0d5d

Please sign in to comment.