Skip to content

Commit

Permalink
refactor: remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vsgoulart committed Dec 20, 2024
1 parent 769a2a6 commit 413c082
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,19 @@ function DownloadButton(props) {

/**
*
* @param {import("preact").RefObject<HTMLElement>} ref
* @param {import("preact").RefObject<HTMLElement|null>} ref
* @returns boolean
*/
function useInViewport(ref) {
const [isInViewport, setIsInViewport] = useState(false);

useEffect(() => {
const container = ref.current;

if (!container) {
return;
}

const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
Expand All @@ -295,13 +301,11 @@ function useInViewport(ref) {
},
);

if (ref.current) {
observer.observe(ref.current);
}
observer.observe(container);

return () => {
if (ref.current) {
observer.unobserve(ref.current);
if (container) {
observer.unobserve(container);
}
};
}, [ref]);
Expand Down

0 comments on commit 413c082

Please sign in to comment.