From db37cbdfb34871a81bb8398ddb4b6731f225023f Mon Sep 17 00:00:00 2001 From: Costi Date: Wed, 11 Sep 2024 12:35:56 +0300 Subject: [PATCH] update ref when handleInputChange is changing --- src/components/inputs/Autocomplete/Autocomplete.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/inputs/Autocomplete/Autocomplete.tsx b/src/components/inputs/Autocomplete/Autocomplete.tsx index a362e76e..a89b4e00 100644 --- a/src/components/inputs/Autocomplete/Autocomplete.tsx +++ b/src/components/inputs/Autocomplete/Autocomplete.tsx @@ -277,8 +277,10 @@ const Autocomplete: React.FC> = ({ if (event?.nativeEvent?.type === 'focusout') { return } + + await handleLoadOptions(value) }, - [onInputChange] + [handleLoadOptions, onInputChange] ) useEffect(() => { @@ -325,7 +327,12 @@ const Autocomplete: React.FC> = ({ 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 (