Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-aria/virtualizer

Package Overview
Dependencies
Maintainers
2
Versions
843
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/virtualizer

Spectrum UI components in React

  • 3.3.2-nightly.2613
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
339K
increased by4.72%
Maintainers
2
Weekly downloads
 
Created

What is @react-aria/virtualizer?

@react-aria/virtualizer is a library that provides utilities for efficiently rendering large lists and collections in React applications. It leverages virtualization techniques to only render the visible items, improving performance and reducing memory usage.

What are @react-aria/virtualizer's main functionalities?

Virtualized List

This feature allows you to create a virtualized list where only the visible items are rendered. This improves performance for large lists by reducing the number of DOM elements.

import { useVirtualizer } from '@react-aria/virtualizer';
import { useRef } from 'react';

function VirtualizedList({ items }) {
  const parentRef = useRef();
  const { virtualItems, totalSize } = useVirtualizer({
    count: items.length,
    getScrollElement: () => parentRef.current,
    estimateSize: () => 35
  });

  return (
    <div ref={parentRef} style={{ overflow: 'auto', height: '400px' }}>
      <div style={{ height: totalSize }}>
        {virtualItems.map(virtualRow => (
          <div
            key={virtualRow.index}
            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 items are rendered. This is useful for displaying large grids of items efficiently.

import { useVirtualizer } from '@react-aria/virtualizer';
import { useRef } from 'react';

function VirtualizedGrid({ items, columnCount }) {
  const parentRef = useRef();
  const { virtualItems, totalSize } = useVirtualizer({
    count: items.length,
    getScrollElement: () => parentRef.current,
    estimateSize: () => 100
  });

  return (
    <div ref={parentRef} style={{ overflow: 'auto', height: '400px' }}>
      <div style={{ height: totalSize }}>
        {virtualItems.map(virtualItem => (
          <div
            key={virtualItem.index}
            style={{
              position: 'absolute',
              top: 0,
              left: 0,
              width: `${100 / columnCount}%`,
              transform: `translate(${(virtualItem.index % columnCount) * 100}%, ${Math.floor(virtualItem.index / columnCount) * 100}px)`
            }}
          >
            {items[virtualItem.index]}
          </div>
        ))}
      </div>
    </div>
  );
}

Other packages similar to @react-aria/virtualizer

FAQs

Package last updated on 02 Mar 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc