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