{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-delayed-loading",
  "title": "Use Delayed Loading",
  "description": "Delays a loading flag and holds it briefly so quick loads never flash.",
  "files": [
    {
      "path": "registry/hooks/use-delayed-loading.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\ntype DelayedLoadingOptions = {\n  /** Wait this long (ms) before showing anything; loads that finish sooner never flash a placeholder. */\n  delay?: number\n  /** Once shown, keep it at least this long (ms) so it doesn't blink away. */\n  minDuration?: number\n}\n\ntype Phase = \"idle\" | \"waiting\" | \"shown\" | \"held\"\n\n/**\n * Turns a `loading` flag into one that is safe to show: false for quick loads,\n * and once true, true for at least `minDuration`. Feed the result to `loading`\n * on Button, Skeleton, RecordTable or a chart. On a screen's first load, where\n * there is nothing to keep, pass `loading` straight through instead.\n */\nfunction useDelayedLoading(loading: boolean, { delay = 300, minDuration = 400 }: DelayedLoadingOptions = {}) {\n  // waiting: loading, not shown yet. shown: on screen, minimum not reached. held: minimum reached, shown while loading.\n  const [phase, setPhase] = React.useState<Phase>(\"idle\")\n\n  if (loading && phase === \"idle\") setPhase(\"waiting\")\n  else if (!loading && (phase === \"waiting\" || phase === \"held\")) setPhase(\"idle\")\n\n  React.useEffect(() => {\n    if (phase !== \"waiting\" && phase !== \"shown\") return\n    const timer = window.setTimeout(() => setPhase(phase === \"waiting\" ? \"shown\" : \"held\"), phase === \"waiting\" ? delay : minDuration)\n    return () => window.clearTimeout(timer)\n  }, [phase, delay, minDuration])\n\n  return phase === \"shown\" || phase === \"held\"\n}\n\nexport { useDelayedLoading, type DelayedLoadingOptions }\n",
      "type": "registry:hook",
      "target": "@hooks/use-delayed-loading.ts"
    }
  ],
  "docs": "https://builders.ikas.com/tr/docs/app-development/ui-kit/components/primitives",
  "categories": [
    "feedback",
    "utilities"
  ],
  "type": "registry:hook"
}