npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pyreon/virtual

v0.12.1

Published

Pyreon adapter for TanStack Virtual

Downloads

2,935

Readme

@pyreon/virtual

Pyreon adapter for TanStack Virtual. Efficient rendering of large lists with reactive virtualItems, totalSize, and isScrolling signals.

Install

bun add @pyreon/virtual @tanstack/virtual-core

Quick Start

import { signal } from '@pyreon/reactivity'
import { useVirtualizer } from '@pyreon/virtual'

function VirtualList() {
  const parentRef = signal<HTMLElement | null>(null)
  const items = Array.from({ length: 10000 }, (_, i) => `Item ${i + 1}`)

  const { virtualItems, totalSize } = useVirtualizer(() => ({
    count: items.length,
    getScrollElement: () => parentRef(),
    estimateSize: () => 40,
    overscan: 5,
  }))

  return () => (
    <div ref={(el) => parentRef.set(el)} style="height: 400px; overflow-y: auto;">
      <div style={`height: ${totalSize()}px; position: relative;`}>
        {virtualItems().map((row) => (
          <div
            key={row.key}
            style={`position: absolute; top: 0; width: 100%; height: ${row.size}px; transform: translateY(${row.start}px);`}
          >
            {items[row.index]}
          </div>
        ))}
      </div>
    </div>
  )
}

API

useVirtualizer(options)

Create a reactive virtualizer for element-based scrolling. Options are passed as a function so reactive signals can be read inside, and the virtualizer updates automatically when they change.

| Parameter | Type | Description | | --------- | ----------------------------- | ------------------------------------- | | options | () => UseVirtualizerOptions | Function returning virtualizer config |

Options extend VirtualizerOptions from @tanstack/virtual-core with observeElementRect, observeElementOffset, and scrollToFn pre-filled (overridable).

Returns: UseVirtualizerResult with:

| Property | Type | Description | | -------------- | ----------------------- | -------------------------------------------- | | instance | Virtualizer | The underlying TanStack Virtualizer instance | | virtualItems | Signal<VirtualItem[]> | Currently visible virtual items | | totalSize | Signal<number> | Total scrollable size in pixels | | isScrolling | Signal<boolean> | Whether the user is currently scrolling |

const parentRef = signal<HTMLDivElement | null>(null)
const count = signal(1000)

const { virtualItems, totalSize, isScrolling, instance } = useVirtualizer(() => ({
  count: count(),
  getScrollElement: () => parentRef(),
  estimateSize: () => 35,
  overscan: 5,
}))

// Scroll programmatically:
instance.scrollToIndex(500)

useWindowVirtualizer(options)

Create a reactive virtualizer for window-based scrolling. The scroll element is automatically set to window. SSR-safe — checks for window and document availability.

| Parameter | Type | Description | | --------- | ----------------------------------- | -------------------------------------------------------- | | options | () => UseWindowVirtualizerOptions | Function returning config (no getScrollElement needed) |

Returns: UseWindowVirtualizerResult — same shape as UseVirtualizerResult but typed with Window as the scroll element.

function WindowList() {
  const items = Array.from({ length: 50000 }, (_, i) => `Row ${i}`)

  const { virtualItems, totalSize } = useWindowVirtualizer(() => ({
    count: items.length,
    estimateSize: () => 40,
  }))

  return () => (
    <div style={`height: ${totalSize()}px; position: relative;`}>
      {virtualItems().map((row) => (
        <div
          key={row.key}
          style={`position: absolute; top: 0; width: 100%; height: ${row.size}px; transform: translateY(${row.start}px);`}
        >
          {items[row.index]}
        </div>
      ))}
    </div>
  )
}

Patterns

Dynamic Item Sizes

Use measureElement for variable-height items that are measured after render.

import { measureElement } from '@pyreon/virtual'

const { virtualItems, totalSize, instance } = useVirtualizer(() => ({
  count: items.length,
  getScrollElement: () => parentRef(),
  estimateSize: () => 50,
  measureElement,
}))

// In render, set the ref on each item:
virtualItems().map((row) => (
  <div key={row.key} ref={(el) => instance.measureElement(el)} data-index={row.index}>
    {items[row.index]}
  </div>
))

Horizontal Lists

Set the horizontal option for horizontal virtualization.

const { virtualItems, totalSize } = useVirtualizer(() => ({
  count: columns.length,
  getScrollElement: () => parentRef(),
  estimateSize: () => 120,
  horizontal: true,
}))

Reactive Count

Since options are a function, changing the count signal re-calculates virtual items automatically.

const filteredItems = signal(allItems)
const { virtualItems } = useVirtualizer(() => ({
  count: filteredItems().length,
  getScrollElement: () => parentRef(),
  estimateSize: () => 40,
}))

// Updating filteredItems triggers recalculation
filteredItems.set(allItems.filter((i) => i.includes(search())))

Re-exports from @tanstack/virtual-core

Runtime: defaultKeyExtractor, defaultRangeExtractor, observeElementOffset, observeElementRect, observeWindowOffset, observeWindowRect, elementScroll, windowScroll, measureElement, Virtualizer

Types: VirtualizerOptions, VirtualItem, Range, Rect, ScrollToOptions

Gotchas

  • Options must be a function () => opts for reactive tracking. The virtualizer re-calculates when signals read inside the function change.
  • The instance is the raw TanStack Virtualizer — use it for imperative methods like scrollToIndex() and scrollToOffset().
  • virtualItems, totalSize, and isScrolling are Pyreon signals updated via batch() for efficient reactive notifications.
  • The virtualizer's DOM observers are mounted via onMount and cleaned up via onUnmount. The component must be mounted for scroll observation to work.
  • useWindowVirtualizer checks for window availability and provides a safe fallback for SSR.