Updates
This commit is contained in:
parent
9f8527fc4d
commit
2c101420cc
@ -1,4 +1,4 @@
|
||||
import React from "react";
|
||||
import React, { useRef } from "react";
|
||||
|
||||
type Param = {
|
||||
elementRef?: React.RefObject<Element | undefined>;
|
||||
@ -9,8 +9,6 @@ type Param = {
|
||||
delay?: number;
|
||||
};
|
||||
|
||||
let timeout: any;
|
||||
|
||||
export default function useIntersectionObserver({
|
||||
elementRef,
|
||||
className,
|
||||
@ -19,6 +17,8 @@ export default function useIntersectionObserver({
|
||||
delay,
|
||||
elId,
|
||||
}: Param) {
|
||||
let timeoutRef = useRef<any>(null);
|
||||
|
||||
const [isIntersecting, setIsIntersecting] = React.useState(false);
|
||||
const [refresh, setRefresh] = React.useState(0);
|
||||
|
||||
@ -27,10 +27,10 @@ export default function useIntersectionObserver({
|
||||
const observerCallback: IntersectionObserverCallback = React.useCallback(
|
||||
(entries, observer) => {
|
||||
const entry = entries[0];
|
||||
window.clearTimeout(timeout);
|
||||
window.clearTimeout(timeoutRef.current);
|
||||
|
||||
if (entry.isIntersecting) {
|
||||
timeout = setTimeout(() => {
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setIsIntersecting(true);
|
||||
|
||||
if (removeIntersected) {
|
||||
@ -41,7 +41,7 @@ export default function useIntersectionObserver({
|
||||
setIsIntersecting(false);
|
||||
}
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user