Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 1.09 KB

use-timeout.mdx

File metadata and controls

50 lines (39 loc) · 1.09 KB
group package category title order slug description import docs source
mantine-hooks
@mantine/hooks
state
use-timeout
1
/hooks/use-timeout/
Calls function after given timeout
import { useTimeout } from '@mantine/hooks';
hooks/use-timeout.mdx
mantine-hooks/src/use-timeout/use-timeout.ts

import { HooksDemos } from '@mantine/demos';

Usage

API

const { start, clear } = useTimeout(callback, delay, { autoInvoke: true });

Arguments:

  • callback – function that will be called after the timer elapses
  • delay – number of milliseconds the timer should wait before the specified function is executed
  • options: { autoInvoke } - determines whether the timer should be started on mount, defaults to false

Return object:

  • start - starts the timer
  • clear – cancels the timer

Definition

function useTimeout(
  callback: (...callbackParams: any[]) => void,
  delay: number,
  options?: {
    autoInvoke: boolean;
  }
): {
  start: (...callbackParams: any[]) => void;
  clear: () => void;
};