Skip to content
2 changes: 1 addition & 1 deletion src/hooks/useDebouncedCallback/ko/useDebouncedCallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function useDebouncedCallback(options: Object): Function;
:nested="[
{
name: 'options.onChange',
type: 'Function',
type: '(newValue: T) => void',
required: true,
description: '디바운스할 콜백 함수예요.',
},
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useDebouncedCallback/useDebouncedCallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function useDebouncedCallback(options: Object): Function;
:nested="[
{
name: 'options.onChange',
type: 'Function',
type: '(newValue: T) => void',
required: true,
description: 'The callback function to debounce.',
},
Expand Down
11 changes: 7 additions & 4 deletions src/hooks/useDebouncedCallback/useDebouncedCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ type DebounceOptions = {
* return <input type="text" onChange={(e) => debouncedSetQuery(e.target.value)} />;
* }
*/
export function useDebouncedCallback({
export function useDebouncedCallback<T>({
onChange,
timeThreshold,
leading = false,
trailing = true,
}: DebounceOptions & {
onChange: (newValue: boolean) => void;
onChange: (newValue: T) => void;
timeThreshold: number;
}) {
const handleChange = usePreservedCallback(onChange);
const ref = useRef({ value: false, clearPreviousDebounce: () => {} });
const ref = useRef<{ value: T | null; clearPreviousDebounce: () => void }>({
value: null,
clearPreviousDebounce: () => {},
});

useEffect(() => {
const current = ref.current;
Expand All @@ -63,7 +66,7 @@ export function useDebouncedCallback({
}, [leading, trailing]);

return useCallback(
(nextValue: boolean) => {
(nextValue: T) => {
if (nextValue === ref.current.value) {
return;
}
Expand Down
Loading