
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
virtual-scroll-component
Advanced tools
Virtual and infinite scrolling for a list of elements. A wrapper component to be used in the React framework.
Rendering hundreds of elements in DOM can be slow, especially if your elements are non-trivial. Instead, we can simply render elements as necessary when they are scrolled into view. This is called virtual scrolling.

As you can imagine, rendering only view-able elements can cause unnecessary document scrolling as the position of HTML elements are usually relative. We can fix this by wrapping a container with fixed height around every element, and only render the child element when necessary.
npm install virtual-scroll-component
yarn add virtual-scroll-component
import VirtualScroll from 'virtual-scroll-component';
Use rows to pass an array of component instances to be placed in a virtualized scroll container. This can also be done with props.children, but do note that any arguments passed to props.children takes precedence over rows.
<VirtualScroll rows={[<div/>, <div/>]}/>
<VirtualScroll rows={[<span/>]}>
<div/> // div will be used, and not span
</VirtualScroll>
Use rowHeight to set the height of each row. Accepts an integer and is interpreted in CSS pixels.
<VirtualScroll rowHeight={100}/>
Use onLastRow to set a function to be called every time the last row is in view. You can pass a function which increases the number of component instances, thereby creating an infinite scroll.
const [rows, setRows] = useState([<Child/>]);
const handleLastRow = () => {
setRows([...rows, <Child/>])
}
return (<VirtualScroll rows={rows} onLastRow={handleLastRow}/>);
Use className to add a CSS class onto the VirtualScroll component. By default, elements are rendered vertically. Use className to override default styles.
<VirtualScroll className={"custom-class-name"}/>
Use props.children to pass a list of component instances to be placed in a virtualized scroll container. This can also be done with rows, but do note that any arguments passed to props.children takes precedence over rows.
<VirtualScroll>
<div/>
<div/>
</VirtualScroll>
This package does not support elements with varying heights.
There are some scripts available in package.json.
yarn start - to watch for file changes and update automatically with webpackyarn build - to build the package and store in ./dist/index.jsyarn jest - to run unit testsI welcome any from of participation, so feel free to submit an issue or make a pull request.
Big thanks to BP mishra for his guidance throughout this project!
FAQs
A container component for virtualized scroll.
The npm package virtual-scroll-component receives a total of 90 weekly downloads. As such, virtual-scroll-component popularity was classified as not popular.
We found that virtual-scroll-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.