everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
27 lines (25 loc) • 712 B
JavaScript
let react = require("react");
let _tanstack_react_router = require("@tanstack/react-router");
//#region src/ui/use-scroll-to-hash.ts
function useScrollToHash(id) {
const hash = (0, _tanstack_react_router.useLocation)({ select: (location) => location.hash });
const [target, setTarget] = (0, react.useState)(null);
const scrolled = (0, react.useRef)(false);
(0, react.useEffect)(() => {
if (hash !== id) {
scrolled.current = false;
return;
}
if (!target || scrolled.current) return;
scrolled.current = true;
target.scrollIntoView();
}, [
hash,
id,
target
]);
return setTarget;
}
//#endregion
exports.useScrollToHash = useScrollToHash;
//# sourceMappingURL=use-scroll-to-hash.cjs.map