use-interval
Utility hook for creating intervals with auto-cleanup.
Installation
npx shadcn add @limeplay/use-intervalUsage
import { useInterval } from "@/hooks/limeplay/use-interval"
function PollingComponent() {
useInterval(() => {
console.log("Polling...")
}, 1000)
}Conditional Interval
Pass null as the delay to pause the interval:
const [active, setActive] = useState(true)
useInterval(
() => {
console.log("tick")
},
active ? 500 : null
)The interval is automatically cleaned up on unmount. The callback ref is stable — updated callbacks are picked up without restarting the interval.