Get Started
Components
Infinite Scroll
An Infinite Scroll component is a user interface feature that automatically loads and displays additional content as the user scrolls down a page. Instead of traditional pagination, this component creates a seamless browsing experience by continuously appending new items, such as images or articles, when the user reaches the bottom of the viewport. This enhances user engagement and keeps the content flow uninterrupted, making it ideal for applications like social media feeds, product galleries, and news websites.
Demo
Item 0
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Usage
import { NCard, NInfiniteScroll, NLoading } from '@nayan-ui/react';import React, { useState } from 'react';const InfiniteScroll = () => {const [items, setItems] = useState(new Array(20).fill(''));const [isFetching, setIsFetching] = useState(false);const fetchNextPage = () => {setIsFetching(true);setTimeout(() => {const newItems = [...items, ...new Array(20).fill('')];setItems(newItems);setIsFetching(false);}, 2000);};return (<NInfiniteScrollnext={() => !isFetching && fetchNextPage()}hasMore={true}loader={<NLoading />}dataLength={items.length}scrollThreshold={0.99}>{items.map((item: any, index: number) => (<NCard className="p-3 mb-3">Item {index}</NCard>))}</NInfiniteScroll>);};export default InfiniteScroll;
Attributes
| Name | Type | Default | Details |
|---|---|---|---|
| next | function | Required | Function to load next set of data. |
| hasMore | boolean | Required | Whether there is more data to load. |
| children | React.ReactNode | Required | Content to display in the scroll container. |
| loader | React.ReactNode | Required | Loading indicator component. |
| scrollThreshold | number | string | Optional | Threshold for triggering next load. |
| endMessage | React.ReactNode | Optional | Message to show when no more data. |
| style | CSSProperties | Optional | Custom styles for the container. |
| height | number | string | Optional | Height of the scroll container. |
| scrollableTarget | HTMLElement | string | null | Optional | Target element for scrolling. |
| hasChildren | boolean | Optional | Whether container has children. |
| inverse | boolean | Optional | Whether to use inverse scrolling. |
| pullDownToRefresh | boolean | Optional | Enable pull to refresh functionality. |
| pullDownToRefreshContent | React.ReactNode | Optional | Content for pull to refresh. |
| releaseToRefreshContent | React.ReactNode | Optional | Content for release to refresh. |
| pullDownToRefreshThreshold | number | Optional | Threshold for pull to refresh. |
| refreshFunction | function | Optional | Function to call on refresh. |
| onScroll | (e: Event) => any | Optional | Scroll event handler. |
| dataLength | number | Required | Length of current data array. |
| initialScrollY | number | Optional | Initial scroll position. |
| className | string | ' ' | You can customise by passing tailwind classes. |
| aria-label | string | Optional | ARIA label for accessibility. |