Skip to content

Instantly share code, notes, and snippets.

View gustavofabro's full-sized avatar
🏠
Working from home

Gustavo Fabro gustavofabro

🏠
Working from home
View GitHub Profile
@gustavofabro
gustavofabro / intersection-observer-ex3.tsx
Created October 23, 2021 11:31
Uso da flag isIntersecting
if (!entries[0].isIntersecting) {
return;
}
// Função responsável por carregar mais itens
@gustavofabro
gustavofabro / intersection-observer-ex4.tsx
Last active October 26, 2021 12:15
Uso da flag isLoading
function App() {
const [isLoading, setIsLoading] = useState(false);
// Restante do código
useEffect(() => {
const observer = new IntersectionObserver(
(entries: IntersectionObserverEntry[]) => {
if (!entries[0].isIntersecting || isLoading) {
return;
@gustavofabro
gustavofabro / intersection-observer-ex2.tsx
Last active October 23, 2021 11:19
useEffect IntersectionObserver
useEffect(() => {
const observer = new IntersectionObserver(
(entries: IntersectionObserverEntry[]) => {
// Função responsável por carregar mais itens
},
{
root: null,
rootMargin: '0px',
threshold: 0
});
function App() {
const loadingElementRef = useRef<HTMLDivElement>(null);
// Restante do código
return (
<main className="app">
<div className="list">
{data.map(item => (
<div key={item.id} className="item">{`Item ${item.id + 1}`}</div>