Skip to content

Commit

Permalink
Merge pull request #131 from osstotalsoft/feature/fixAutocompleteLoad…
Browse files Browse the repository at this point in the history
…Options

update ref when handleInputChange is changing
  • Loading branch information
DCosti authored Sep 11, 2024
2 parents 5eb6816 + db37cbd commit 78b65c0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/inputs/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ const Autocomplete: React.FC<AutocompleteProps<any, any, any, any>> = ({
if (event?.nativeEvent?.type === 'focusout') {
return
}

await handleLoadOptions(value)
},
[onInputChange]
[handleLoadOptions, onInputChange]
)

useEffect(() => {
Expand Down Expand Up @@ -325,7 +327,12 @@ const Autocomplete: React.FC<AutocompleteProps<any, any, any, any>> = ({
return simpleValue ? getSimpleValue(loadOptions ? asyncOptions : options, value, valueKey, isMultiSelection) : value
}, [simpleValue, loadOptions, asyncOptions, options, value, valueKey, isMultiSelection])

const throttledOnInputChange = useRef(throttle(handleInputChange, 500)).current
const inputChangeRef = useRef(throttle(handleInputChange, 500))
const throttledOnInputChange = inputChangeRef.current

useEffect(() => {
inputChangeRef.current = throttle(handleInputChange, 500)
}, [handleInputChange])

return (
<MuiAutocomplete
Expand Down

0 comments on commit 78b65c0

Please sign in to comment.