Skip to content

Commit

Permalink
refactor: use debounce 훅 내부 로직 use timeout 훅으로 수정 (#ATR-597)
Browse files Browse the repository at this point in the history
  • Loading branch information
LC-02s committed Aug 18, 2024
1 parent a02e47f commit d78d5f1
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React from 'react'
import { useTimeout } from '../use-timeout'

export default function useDebounce<T>(value: T, delay: number) {
const { start } = useTimeout()
const [debouncedValue, setDebouncedValue] = React.useState<T>(value)

React.useEffect(() => {
const timeoutId = setTimeout(() => setDebouncedValue(value), delay)

return () => {
clearTimeout(timeoutId)
}
start(() => setDebouncedValue(value), delay)
}, [value, delay])

return debouncedValue
Expand Down

0 comments on commit d78d5f1

Please sign in to comment.