Skip to content

Instantly share code, notes, and snippets.

@gustavofabro
Last active October 23, 2021 11:19
Show Gist options
  • Save gustavofabro/fc445dec68f25364d211b3cc9bf047b5 to your computer and use it in GitHub Desktop.
Save gustavofabro/fc445dec68f25364d211b3cc9bf047b5 to your computer and use it in GitHub Desktop.
useEffect IntersectionObserver
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