{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-counter",
  "type": "registry:hook",
  "title": "useCounter",
  "description": "Clamped counter hook. A non-UI item, so it lands at the hooks alias rather than the ui alias.",
  "files": [
    {
      "path": "registry/hooks/use-counter.ts",
      "type": "registry:hook",
      "content": "import * as React from \"react\"\n\nexport type UseCounterOptions = {\n  min?: number\n  max?: number\n  step?: number\n}\n\nexport function useCounter(initial = 0, options: UseCounterOptions = {}) {\n  const { min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY, step = 1 } =\n    options\n\n  const clamp = React.useCallback(\n    (n: number) => Math.min(max, Math.max(min, n)),\n    [min, max]\n  )\n\n  const [count, setCount] = React.useState(() => clamp(initial))\n\n  const increment = React.useCallback(\n    () => setCount((c) => clamp(c + step)),\n    [clamp, step]\n  )\n  const decrement = React.useCallback(\n    () => setCount((c) => clamp(c - step)),\n    [clamp, step]\n  )\n  const reset = React.useCallback(() => setCount(clamp(initial)), [clamp, initial])\n  const set = React.useCallback((n: number) => setCount(clamp(n)), [clamp])\n\n  return { count, increment, decrement, reset, set }\n}\n"
    }
  ]
}
