UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 1.07 kB
{"version":3,"file":"index.cjs","names":["useCallbackRef","timeoutId: NodeJS.Timeout | null"],"sources":["../../../../src/hooks/use-timeout/index.ts"],"sourcesContent":["\"use client\"\n\nimport { useEffect } from \"react\"\nimport { useCallbackRef } from \"../../utils\"\n\n/**\n * `useTimeout` is a custom hook that executes a function after a specified number of milliseconds.\n *\n * @see https://yamada-ui.com/docs/hooks/use-timeout\n */\nexport const useTimeout = (\n callback: (...args: any[]) => void,\n delay: null | number,\n) => {\n const callbackRef = useCallbackRef(callback)\n\n useEffect(() => {\n if (delay == null) return undefined\n\n let timeoutId: NodeJS.Timeout | null = null\n\n timeoutId = setTimeout(callbackRef, delay)\n\n return () => {\n clearTimeout(timeoutId)\n }\n }, [delay, callbackRef])\n}\n"],"mappings":";;;;;;;;;;;;;;AAUA,MAAa,cACX,UACA,UACG;CACH,MAAM,cAAcA,2BAAe,SAAS;AAE5C,4BAAgB;AACd,MAAI,SAAS,KAAM,QAAO;EAE1B,IAAIC,YAAmC;AAEvC,cAAY,WAAW,aAAa,MAAM;AAE1C,eAAa;AACX,gBAAa,UAAU;;IAExB,CAAC,OAAO,YAAY,CAAC"}