use-timeout

use-timeout

타이머를 시작하고 해제(clear)할 수 있게 해 주는 훅이에요. 지정한 지연 시간 후에 콜백을 호출해요.

출처: 문서

본문

사용법 (Usage)

인자(Arguments):

  • callback – 타이머가 경과한 후 호출되는 함수
  • delay – 지정한 함수가 실행되기 전에 타이머가 기다려야 하는 밀리초 수
  • options: { autoInvoke } – 마운트 시 타이머를 시작할지 결정해요. 기본값은 false예요

반환 객체(Return object):

  • start – 타이머를 시작해요
  • clear – 타이머를 취소해요

정의 (Definition)

interface UseTimeoutOptions {
  autoInvoke: boolean;
}

interface UseTimeoutReturnValue {
  start: (...args: any[]) => void;
  clear: () => void;
}

function useTimeout(
  callback: (...args: any[]) => void,
  delay: number,
  options?: UseTimeoutOptions,
): UseTimeoutReturnValue

내보내는 타입 (Exported types)

UseTimeoutOptions와 UseTimeoutReturnValue 타입은 @mantine/hooks에서 내보내져요:

import type { UseTimeoutOptions, UseTimeoutReturnValue } from '@mantine/hooks';

더 알아보기 (Learn more)