{
  "name": "use-previous",
  "author": "Brendan Dash (https://shadcn-hooks.com)",
  "description": "A hook to get the previous value of a variable",
  "files": [
    {
      "path": "registry/hooks/use-previous.ts",
      "content": "import { useRef } from 'react'\n\nexport type ShouldUpdateFunc<T> = (prev?: T, next?: T) => boolean\n\nconst defaultShouldUpdate = <T>(a?: T, b?: T) => !Object.is(a, b)\n\nfunction usePrevious<T>(\n  state: T,\n  shouldUpdate: ShouldUpdateFunc<T> = defaultShouldUpdate,\n): T | undefined {\n  const prevRef = useRef<T>(undefined)\n  const curRef = useRef<T>(undefined)\n\n  if (shouldUpdate(curRef.current, state)) {\n    prevRef.current = curRef.current\n    curRef.current = state\n  }\n\n  return prevRef.current\n}\n\nexport default usePrevious\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}
