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';
const { start, clear } = useTimeout(callback, delay, { autoInvoke: true });
Arguments:
callback
– function that will be called after the timer elapsesdelay
– number of milliseconds the timer should wait before the specified function is executedoptions: { autoInvoke }
- determines whether the timer should be started on mount, defaults to false
Return object:
start
- starts the timerclear
– cancels the timer
function useTimeout(
callback: (...callbackParams: any[]) => void,
delay: number,
options?: {
autoInvoke: boolean;
}
): {
start: (...callbackParams: any[]) => void;
clear: () => void;
};