import { useState, useEffect } from "react"; export default function ToApp() { const [showButton, setShowButton] = useState(true); useEffect(() => { const handleScroll = () => { if (window.scrollY < 2) { setShowButton(true); } else { setShowButton(false); } }; window.addEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll); }, []); return ( <> {showButton && (
Try it!
)} ); };