Skip to content

1.1.2 infinity loader example

Latest
Compare
Choose a tag to compare
@Morglod Morglod released this 28 Jul 20:35
  • Hooks now also return itemSlice

Example infinity loader:

const [items, setItems] = useState([] as any[]);

// here we get current rendered itemSlice
const { renderedItems, itemSlice } = useVirtualOverflowY({
    itemsLengthY: items.length,
    // ...
});

// here we check if we render bottom range of items
useEffect(() => {
    if (itemSlice.topStartIndex + itemSlice.lengthY >= items.length - 4) {
        // load more
        setItems((prev) => [...prev, ...newItems]);
    }
}, [itemSlice.topStartIndex, itemSlice.lengthY]);