Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-virtual
Advanced tools
The react-virtual package is a lightweight and performant library for rendering large lists and tabular data in React applications. It helps in efficiently managing and displaying large datasets by only rendering the visible items, thus improving performance and reducing memory usage.
Virtualized List
This feature allows you to create a virtualized list where only the visible items are rendered. This improves performance when dealing with large datasets.
import { useVirtual } from 'react-virtual';
function VirtualizedList({ items }) {
const parentRef = React.useRef();
const rowVirtualizer = useVirtual({
size: items.length,
parentRef,
estimateSize: React.useCallback(() => 35, []),
});
return (
<div ref={parentRef} style={{ height: `400px`, overflow: 'auto' }}>
<div style={{ height: `${rowVirtualizer.totalSize}px`, width: '100%' }}>
{rowVirtualizer.virtualItems.map(virtualRow => (
<div
key={virtualRow.index}
ref={virtualRow.measureRef}
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
transform: `translateY(${virtualRow.start}px)`
}}
>
{items[virtualRow.index]}
</div>
))}
</div>
</div>
);
}
Virtualized Grid
This feature allows you to create a virtualized grid where only the visible cells are rendered. This is useful for rendering large tables or grids efficiently.
import { useVirtual } from 'react-virtual';
function VirtualizedGrid({ columns, rows }) {
const parentRef = React.useRef();
const columnVirtualizer = useVirtual({
size: columns.length,
parentRef,
estimateSize: React.useCallback(() => 100, []),
horizontal: true,
});
const rowVirtualizer = useVirtual({
size: rows.length,
parentRef,
estimateSize: React.useCallback(() => 35, []),
});
return (
<div ref={parentRef} style={{ height: `400px`, width: `600px`, overflow: 'auto' }}>
<div
style={{
height: `${rowVirtualizer.totalSize}px`,
width: `${columnVirtualizer.totalSize}px`,
position: 'relative',
}}
>
{rowVirtualizer.virtualItems.map(virtualRow => (
<div
key={virtualRow.index}
ref={virtualRow.measureRef}
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
transform: `translateY(${virtualRow.start}px)`
}}
>
{columnVirtualizer.virtualItems.map(virtualColumn => (
<div
key={virtualColumn.index}
ref={virtualColumn.measureRef}
style={{
position: 'absolute',
top: 0,
left: 0,
height: '100%',
transform: `translateX(${virtualColumn.start}px)`
}}
>
{rows[virtualRow.index][virtualColumn.index]}
</div>
))}
</div>
))}
</div>
</div>
);
}
react-window is a library for rendering large lists and tabular data efficiently. It is similar to react-virtual in that it only renders the visible items, but it is more lightweight and has a simpler API. However, react-virtual offers more flexibility and customization options.
react-virtualized is another popular library for rendering large lists and tabular data. It offers a wide range of features and components, including grids, lists, tables, and more. Compared to react-virtual, react-virtualized is more feature-rich but also more complex and heavier.
Table of Contents generated with DocToc
Hooks for virtualizing scrollable elements in React
Enjoy this library? Try the entire TanStack! React Query, React Table, React Charts, React Form
FAQs
Hooks for virtualizing scrollable elements in React
The npm package react-virtual receives a total of 219,054 weekly downloads. As such, react-virtual popularity was classified as popular.
We found that react-virtual 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.