This is the code to scroll to the top.
const ScrollToTop = () => {
const [showTopBtn, setShowTopBtn] = useState(false);
useEffect(() => {
window.addEventListener("scroll", () => {
if (window.scrollY > 400) {
setShowTopBtn(true);
} else {
setShowTopBtn(false);
}
});
}, []);
const goToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};
return (
<div className="top-to-btm">
{" "}
{showTopBtn && (
<FaAngleUp
className="icon-position icon-style"
onClick={goToTop}
/>
)}{" "}
</div>
);
};
This works fine in a normal window, but in a React Modal it doesn't. What do I have to change to make in work in a Modal. Any help is appreciated.