{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-previous",
  "title": "usePrevious",
  "description": "A hook that returns the value from one render ago, via render-time state adjustment instead of a ref+effect.",
  "files": [
    {
      "path": "src/registry/hooks/use-previous.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\n/**\n * Tracks the LAST DISTINCT value (compared with `Object.is`) — repeated\n * equal values do not advance it, so after a \"flat\" update `previous` still\n * holds the value from before the last real change (which is exactly what\n * direction indicators want). Returns `undefined` on the very\n * first render — there is no \"previous\" before the first one.\n *\n * Implementation note: this is deliberately NOT the classic\n * `useRef` + `useEffect` version (`ref.current = value` written inside an\n * effect, read back during render). That version only updates the ref after\n * the effect has run, so what a given render reads back is \"whatever the\n * last effect happened to leave behind\" — under StrictMode's double-invoke\n * or an interrupted/resumed concurrent render, it is not well-defined which\n * pass wrote the ref last. It also means reading a ref's `.current` during\n * render, which this repo's lint setup treats as a smell (render should stay\n * pure; ref reads/writes belong in effects or event handlers, not scattered\n * across both).\n *\n * Here both the current and the previous value live in state, and the\n * comparison happens during render itself: if `value` changed (checked with\n * `Object.is`, the same equality React uses for its own bailout checks) this\n * render calls `setState` to shift the old current into previous — the\n * official React \"adjust state during render\" pattern, not a forbidden\n * effect-body `setState`. Because the update happens inside the same render\n * pass that noticed the change, the ordering is deterministic regardless of\n * StrictMode or concurrent re-renders, and it never touches a ref outside of\n * an effect.\n */\nexport function usePrevious<T>(value: T): T | undefined {\n  const [state, setState] = React.useState<{ current: T; previous: T | undefined }>({\n    current: value,\n    previous: undefined,\n  })\n\n  if (!Object.is(state.current, value)) {\n    setState({ current: value, previous: state.current })\n  }\n\n  return state.previous\n}\n\nexport default usePrevious\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}