Last active
October 23, 2021 11:19
-
-
Save gustavofabro/fc445dec68f25364d211b3cc9bf047b5 to your computer and use it in GitHub Desktop.
useEffect IntersectionObserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
const observer = new IntersectionObserver( | |
(entries: IntersectionObserverEntry[]) => { | |
// Função responsável por carregar mais itens | |
}, | |
{ | |
root: null, | |
rootMargin: '0px', | |
threshold: 0 | |
}); | |
if (loadingElementRef && loadingElementRef.current) { | |
observer.observe(loadingElementRef.current); | |
} | |
return () => observer.disconnect(); | |
}, [loadingElementRef, loadItems]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment