import React, { useState, useEffect } from 'react'; import { ChevronUp } from 'lucide-react'; const BackToTop: React.FC = () => { const [isVisible, setIsVisible] = useState(false); useEffect(() => { const toggleVisibility = () => { if (window.scrollY > 300) { setIsVisible(true); } else { setIsVisible(false); } }; window.addEventListener('scroll', toggleVisibility); return () => window.removeEventListener('scroll', toggleVisibility); }, []); const scrollToTop = () => { window.scrollTo({ top: 0, behavior: 'smooth', }); }; if (!isVisible) return null; return ( ); }; export default BackToTop;