useInfiniteScroll
Scroll to the bottom of the list to load more items automatically.
Infinite List Item #0
Infinite List Item #1
Infinite List Item #2
Infinite List Item #3
Infinite List Item #4
Infinite List Item #5
Infinite List Item #6
Infinite List Item #7
Infinite List Item #8
Infinite List Item #9
Infinite List Item #10
Infinite List Item #11
Infinite List Item #12
Infinite List Item #13
Infinite List Item #14
Scroll down for more
Usage Example
1import { useState } from 'react';
2import { useInfiniteScroll } from '@danixsoft/hooks';
3
4function Feed() {
5 const [items, setItems] = useState([1, 2, 3]);
6
7 const loadMore = () => {
8 // Fetch more items...
9 setItems(prev => [...prev, 4, 5, 6]);
10 };
11
12 // Attach this ref to the element at the bottom of your list
13 const bottomRef = useInfiniteScroll<HTMLDivElement>(loadMore);
14
15 return (
16 <div style={{ height: '400px', overflow: 'auto' }}>
17 {items.map(i => <div key={i}>Item {i}</div>)}
18
19 <div ref={bottomRef}>Loading more...</div>
20 </div>
21 );
22}