Archive
debounce

debounce

lodashdebounce를 직접 구현한 함수입니다.

Code

services/utils/index.ts
export function debounce(func: Function, wait: number) {
  let timeout: string | number | NodeJS.Timeout | undefined
  return function (...args: any) {
    clearTimeout(timeout)
    timeout = setTimeout(() => {
      func.apply(this, args)
    }, wait)
  }
}

this에서 에러가 난다면, tsconfig.json에서 "noImplicitThis": false를 설정하세요.


© 2023 kidow. All rights reserved.
안녕하세요?