From 48da240e6f6151dd5a30a82f5fb1e9d11a10fa56 Mon Sep 17 00:00:00 2001 From: ssi02014 Date: Fri, 20 Sep 2024 14:05:41 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20useDebounce=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/hooks/useDebouncedInputValue/index.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/react/src/hooks/useDebouncedInputValue/index.ts b/packages/react/src/hooks/useDebouncedInputValue/index.ts index b5114fed2..55eaaf44e 100644 --- a/packages/react/src/hooks/useDebouncedInputValue/index.ts +++ b/packages/react/src/hooks/useDebouncedInputValue/index.ts @@ -1,9 +1,5 @@ import { ChangeEvent, useCallback, useState } from 'react'; -import { - DebounceParameters, - useDebounce, - usePreservedCallback, -} from '../../hooks'; +import { DebounceParameters, useDebounce } from '../../hooks'; interface UseDebouncedInputValueReturnType { value: string; @@ -38,13 +34,7 @@ export function useDebouncedInputValue( const [value, setValue] = useState(''); const [debouncedValue, setDebouncedValue] = useState(''); - const debounceCallback = useCallback((value: string) => { - setDebouncedValue(value); - }, []); - - const debouncedChangeValue = usePreservedCallback( - useDebounce(debounceCallback, wait, options) - ); + const debouncedChangeValue = useDebounce(setDebouncedValue, wait, options); const onChange = useCallback( (e: ChangeEvent) => { @@ -57,8 +47,8 @@ export function useDebouncedInputValue( const onReset = useCallback(() => { setValue(''); - setDebouncedValue(''); - }, []); + debouncedChangeValue(''); + }, [debouncedChangeValue]); return { value, debouncedValue, onChange, onReset }; }