{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-geolocation",
  "title": "UseGeolocation",
  "description": "Declarative wrapper for the Geolocation API.",
  "files": [
    {
      "path": "registry/hooks/use-geolocation.tsx",
      "content": "'use client';\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nexport interface GeolocationState {\n  position: GeolocationPosition | null;\n  error: GeolocationPositionError | null;\n  isLoading: boolean;\n  clearWatch: () => void;\n}\n\nexport function useGeolocation(options?: PositionOptions): GeolocationState {\n  const [position, setPosition] = useState<GeolocationPosition | null>(null);\n  const [error, setError] = useState<GeolocationPositionError | null>(null);\n  const [isLoading, setIsLoading] = useState<boolean>(true);\n\n  const watchId = useRef<number | null>(null);\n\n  const clearWatch = useCallback(() => {\n    if (watchId.current !== null && 'geolocation' in navigator) {\n      navigator.geolocation.clearWatch(watchId.current);\n      watchId.current = null;\n    }\n  }, []);\n\n  useEffect(() => {\n    if (!('geolocation' in navigator)) {\n      setError({\n        code: 0,\n        message: 'Geolocation API not supported',\n      } as GeolocationPositionError);\n      setIsLoading(false);\n      return;\n    }\n\n    const onSuccess = (pos: GeolocationPosition) => {\n      setPosition(pos);\n      setError(null);\n      setIsLoading(false);\n    };\n\n    const onError = (err: GeolocationPositionError) => {\n      setError(err);\n      setPosition(null);\n      setIsLoading(false);\n    };\n\n    navigator.geolocation.getCurrentPosition(onSuccess, onError, options);\n\n    const id = navigator.geolocation.watchPosition(onSuccess, onError, options);\n    watchId.current = id;\n\n    return () => {\n      clearWatch();\n    };\n  }, [options, clearWatch]);\n\n  return { position, error, isLoading, clearWatch };\n}\n",
      "type": "registry:hook",
      "target": "hooks/guarahooks/use-geolocation.tsx"
    }
  ],
  "categories": [
    "utilities"
  ],
  "type": "registry:hook"
}