everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
1 lines • 1.08 kB
Source Map (JSON)
{"version":3,"file":"use-scroll-to-hash.mjs","names":[],"sources":["../../src/ui/use-scroll-to-hash.ts"],"sourcesContent":["import { useLocation } from \"@tanstack/react-router\";\nimport { useEffect, useRef, useState } from \"react\";\n\nexport function useScrollToHash<T extends HTMLElement = HTMLElement>(id: string) {\n const hash = useLocation({ select: (location) => location.hash });\n const [target, setTarget] = useState<T | null>(null);\n const scrolled = useRef(false);\n\n useEffect(() => {\n if (hash !== id) {\n scrolled.current = false;\n return;\n }\n if (!target || scrolled.current) return;\n scrolled.current = true;\n target.scrollIntoView();\n }, [hash, id, target]);\n\n return setTarget;\n}\n"],"mappings":";;;;AAGA,SAAgB,gBAAqD,IAAY;CAC/E,MAAM,OAAO,YAAY,EAAE,SAAS,aAAa,SAAS,KAAK,CAAC;CAChE,MAAM,CAAC,QAAQ,aAAa,SAAmB,IAAI;CACnD,MAAM,WAAW,OAAO,KAAK;CAE7B,gBAAgB;EACd,IAAI,SAAS,IAAI;GACf,SAAS,UAAU;GACnB;EACF;EACA,IAAI,CAAC,UAAU,SAAS,SAAS;EACjC,SAAS,UAAU;EACnB,OAAO,eAAe;CACxB,GAAG;EAAC;EAAM;EAAI;CAAM,CAAC;CAErB,OAAO;AACT"}