Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
fellmann committed Oct 2, 2024
1 parent 10de94f commit 16d3d4d
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useCallback, useRef, useState } from "react";
import { useCallback, useRef, useState } from 'react';

export function useInViewport<T extends HTMLElement>() {
const observer = useRef<IntersectionObserver | null>(null);
const [inViewport, setInViewport] = useState(false);

const ref = useCallback((node: T | null) => {
if (typeof IntersectionObserver !== "undefined") {
if (typeof IntersectionObserver !== 'undefined') {
if (node && !observer.current) {
observer.current = new IntersectionObserver(([entry]) =>
setInViewport(entry.isIntersecting)
);
} else {
observer.current?.disconnect();
}

if (node) {
observer.current?.observe(node);
} else {
Expand Down

0 comments on commit 16d3d4d

Please sign in to comment.