{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "use-interval", "description": "A custom hook to manage intervals.", "registryDependencies": [ "https://reactusekit.vercel.app/r/use-isomorphic-layout-effect.json" ], "files": [ { "path": "src/registry/new-york/hooks/use-interval.ts", "content": "import { useEffect, useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./use-isomorphic-layout-effect\";\n\n/**\n * A custom hook that sets up an interval to call a callback function at specified intervals.\n * @param callback - The function to be called at each interval.\n * @param delay - The time in milliseconds between each call. If null, the interval is not set.\n */\n\nexport function useInterval(callback: () => void, delay: number | null): void {\n const savedCallback = useRef<() => void>(callback);\n\n // Remember the latest callback if it changes.\n useIsomorphicLayoutEffect(() => {\n savedCallback.current = callback;\n }, [callback]);\n\n useEffect(() => {\n if (delay === null || delay < 0) {\n return;\n }\n\n const tick = () => savedCallback.current();\n const id = setInterval(tick, delay);\n\n return () => clearInterval(id);\n }, [delay]);\n}\n", "type": "registry:hook" } ], "type": "registry:hook" }