prevent IntersectionObserver error on unobserve with null ref
This commit is contained in:
parent
425c32750c
commit
89085d5069
@ -106,24 +106,27 @@ const ImageGallery = () => {
|
|||||||
return () => eventBus.off("image_gallery", handler);
|
return () => eventBus.off("image_gallery", handler);
|
||||||
}, [selectedProjectId, refetch]);
|
}, [selectedProjectId, refetch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!loaderRef.current) return;
|
if (!loaderRef.current) return;
|
||||||
const obs = new IntersectionObserver(
|
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
([entry]) => {
|
([entry]) => {
|
||||||
if (
|
if (entry.isIntersecting && hasNextPage && !isFetchingNextPage && !isLoading) {
|
||||||
entry.isIntersecting &&
|
|
||||||
hasNextPage &&
|
|
||||||
!isFetchingNextPage &&
|
|
||||||
!isLoading
|
|
||||||
) {
|
|
||||||
fetchNextPage();
|
fetchNextPage();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ rootMargin: "200px", threshold: 0.1 }
|
{ rootMargin: "200px", threshold: 0.1 }
|
||||||
);
|
);
|
||||||
obs.observe(loaderRef.current);
|
|
||||||
return () => obs.unobserve(loaderRef.current);
|
observer.observe(loaderRef.current);
|
||||||
}, [hasNextPage, isFetchingNextPage, isLoading, fetchNextPage]);
|
|
||||||
|
return () => {
|
||||||
|
if (loaderRef.current) {
|
||||||
|
observer.unobserve(loaderRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [hasNextPage, isFetchingNextPage, isLoading, fetchNextPage]);
|
||||||
|
|
||||||
|
|
||||||
// Utility: derive filter options
|
// Utility: derive filter options
|
||||||
const getUniqueValues = useCallback(
|
const getUniqueValues = useCallback(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user