Skip to content

Commit

Permalink
fix: useDebounce 내부 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 committed Sep 20, 2024
1 parent d172d55 commit 48da240
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/react/src/hooks/useDebouncedInputValue/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<HTMLInputElement>) => {
Expand All @@ -57,8 +47,8 @@ export function useDebouncedInputValue(

const onReset = useCallback(() => {
setValue('');
setDebouncedValue('');
}, []);
debouncedChangeValue('');
}, [debouncedChangeValue]);

return { value, debouncedValue, onChange, onReset };
}

0 comments on commit 48da240

Please sign in to comment.