gigafibre-fsm/apps/website/src/components/ScrollToTop.tsx
louispaulb 8e8b89c531 merge: import site-web-targo into apps/website/ (4 commits preserved)
Integrates www.gigafibre.ca (React/Vite) into the monorepo.
Full git history accessible via `git log -- apps/website/`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 08:09:15 -04:00

23 lines
563 B
TypeScript

import { useEffect } from "react";
import { useLocation } from "react-router-dom";
export const ScrollToTop = () => {
const { pathname, hash } = useLocation();
useEffect(() => {
if (hash) {
// Delay to ensure DOM is rendered before scrolling to hash
setTimeout(() => {
const el = document.querySelector(hash);
if (el) {
el.scrollIntoView({ behavior: "smooth" });
}
}, 150);
} else {
window.scrollTo({ top: 0, left: 0, behavior: "instant" });
}
}, [pathname, hash]);
return null;
};