Skip to content

Commit fb6e4a5

Browse files
committed
Refactor useIsInView to know whether the element is out of view
1 parent 32a3c0b commit fb6e4a5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

dotcom-rendering/src/lib/useIsInView.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ type Options = {
4242
*/
4343
const useIsInView = (
4444
options: IntersectionObserverInit & Options,
45-
): [boolean, React.Dispatch<React.SetStateAction<HTMLElement | null>>] => {
46-
const [isInView, setIsInView] = useState<boolean>(false);
45+
): [
46+
boolean | null,
47+
React.Dispatch<React.SetStateAction<HTMLElement | null>>,
48+
] => {
49+
const [isInView, setIsInView] = useState<boolean | null>(null);
4750
const [node, setNode] = useState<HTMLElement | null>(options.node ?? null);
4851

4952
const observer = useRef<IntersectionObserver | null>(null);

0 commit comments

Comments
 (0)