Skip to content

Commit

Permalink
Merge pull request #43 from returnkirbo/fix-overflow
Browse files Browse the repository at this point in the history
Correctly Reset Body Overflow
  • Loading branch information
Captain Jack Sparrow authored Jun 8, 2024
2 parents 147fad5 + 94faa02 commit d1d1f11
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 d1d1f11

Please sign in to comment.