Files
rheinsw-mono-repo/frontend/hooks/useScrollNavigation.ts
Thatsaphorn Atchariyaphap d9ff535ac0 Improve project structure.
New Project Structure:
  - Created reusable UI components (ServiceCard, AnimatedSection, SectionTitle)
  - Split large components into smaller, focused ones
  - Extracted shared hooks for common functionality
  - Organized constants into separate files

Key Improvements:
  - Hooks: useScrollNavigation, useScrollToSection, useCookieSettings
  - UI Components: Modular components for consistent styling and behavior
  - Constants: Centralized data management (ServicesData, NavigationData)
  - Component Split: Navbar, Hero, and Footer broken into logical sub-components
2025-08-08 19:38:12 +02:00

32 lines
933 B
TypeScript

'use client';
import { usePathname, useRouter } from 'next/navigation';
import { useCallback } from 'react';
export const useScrollNavigation = () => {
const pathname = usePathname();
const router = useRouter();
const handleNavClick = useCallback((id: string) => {
if (typeof window === 'undefined') return;
if (pathname === '/') {
const el = document.getElementById(id);
if (el) {
el.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
} else {
localStorage.setItem('scrollToId', id);
router.push('/');
}
}, [pathname, router]);
const scrollToSection = useCallback((id: string) => {
const el = document.getElementById(id);
if (el) {
el.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}, []);
return { handleNavClick, scrollToSection };
};