React Virtual Scroller Component
Virtual Scroller
A virtual scroller is a UI element that allows users to scroll through a list of items without requiring the entire list to be loaded into memory at once. This can be particularly useful for lists that are very large or that contain a lot of data, as it allows the user to view and interact with a subset of the list while the rest of the data is loaded in the background.
Virtual scrollers work by only rendering the items that are currently visible on the screen, and as the user scrolls through the list, new items are dynamically loaded and added to the view. This helps to reduce the amount of data that needs to be loaded and processed at any given time, which can improve the performance and responsiveness of the UI.
Virtual scroll (10000 Items)#
const [index, setIndex] = useState(0)return ( <CVirtualScroller className="border" visibleItems={20} onScroll={(currentItemIndex) => setIndex(currentItemIndex)}> {Array.from({ length: 10000 }, (_, i) => ( <div key={i}>Option {i + 1}</div> ))} </CVirtualScroller>)
API#
CVirtualScroller#
import { CVirtualScroller } from '@coreui/react-pro'// orimport CVirtualScroller from '@coreui/react-pro/src/components/virtual-scroller/CVirtualScroller'
Property | Description | Type | Default |
---|---|---|---|
className | A string of all className you want applied to the base component. | string | - |
onScroll | Event fires when the component has been scrolled. | (currentItemIndex: number) => void | - |
visibleItems | Amount of visible items | number | - |