[WEB-1481] fix: multiple API calls in inbox issues on closed issues tab. (#4691)

* fix: multiple API calls on scroll and closed issues tab.

* fix: pagination loader on initial load.
This commit is contained in:
Prateek Shourya 2024-06-04 13:18:25 +05:30 committed by GitHub
parent 20acb0dd17
commit 77b73dc032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 39 deletions

View file

@ -9,12 +9,12 @@ export type UseIntersectionObserverProps = {
export const useIntersectionObserver = (
containerRef: RefObject<HTMLDivElement>,
elementRef: RefObject<HTMLDivElement>,
elementRef: HTMLDivElement | null,
callback: () => void,
rootMargin?: string
) => {
useEffect(() => {
if (elementRef.current) {
if (elementRef) {
const observer = new IntersectionObserver(
(entries) => {
if (entries[entries.length - 1].isIntersecting) {
@ -26,16 +26,16 @@ export const useIntersectionObserver = (
rootMargin,
}
);
observer.observe(elementRef.current);
observer.observe(elementRef);
return () => {
if (elementRef.current) {
if (elementRef) {
// eslint-disable-next-line react-hooks/exhaustive-deps
observer.unobserve(elementRef.current);
observer.unobserve(elementRef);
}
};
}
// while removing the current from the refs, the observer is not not working as expected
// fix this eslint warning with caution
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rootMargin, callback, elementRef.current, containerRef.current]);
}, [rootMargin, callback, elementRef, containerRef.current]);
};