UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

27 lines (25 loc) • 649 B
import { useEffect, useRef, useState } from "react"; import { useLocation } from "@tanstack/react-router"; //#region src/ui/use-scroll-to-hash.ts function useScrollToHash(id) { const hash = useLocation({ select: (location) => location.hash }); const [target, setTarget] = useState(null); const scrolled = useRef(false); useEffect(() => { if (hash !== id) { scrolled.current = false; return; } if (!target || scrolled.current) return; scrolled.current = true; target.scrollIntoView(); }, [ hash, id, target ]); return setTarget; } //#endregion export { useScrollToHash }; //# sourceMappingURL=use-scroll-to-hash.mjs.map