Skip to content

Commit

Permalink
correctly reset overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbytxt committed Jun 8, 2024
1 parent 147fad5 commit 94faa02
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/pages/Discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,14 @@ export function Discover() {
}

const [isHovered, setIsHovered] = useState(false);

const handleMouseEnter = () => {
document.body.style.overflow = "hidden";
setIsHovered(true);
};

const handleMouseLeave = () => {
setIsHovered(false);
};
const toggleHover = (isHovering: boolean) => setIsHovered(isHovering);

useEffect(() => {
if (!isHovered) {
document.body.style.overflow = isHovered ? "hidden" : "auto";

return () => {
document.body.style.overflow = "auto";
}
};
}, [isHovered]);

function renderMovies(medias: Media[], category: string, isTVShow = false) {
Expand Down Expand Up @@ -344,8 +338,8 @@ export function Discover() {
ref={(el) => {
carouselRefs.current[categorySlug] = el;
}}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onMouseEnter={() => toggleHover(true)}
onMouseLeave={() => toggleHover(false)}
onWheel={(e) => handleWheel(e, categorySlug)}
>
{medias
Expand Down

0 comments on commit 94faa02

Please sign in to comment.