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

react-anchorlist

v0.3.15

Published

High-performance chat virtualizer for React — no flicker, no hacks

Readme

react-anchorlist

High-performance virtualized lists for React, optimized for chat and infinite feeds.

No flicker when prepending older messages. Stable scroll. Simple API.

npm install react-anchorlist

Why use it

  • Virtualizes large lists (renders only what is visible + overscan)
  • Keeps scroll stable when you prepend items (chat history)
  • Supports top/bottom pagination callbacks
  • Includes chat-focused behavior like followOutput and declarative scroll commands
  • Works with dynamic row heights via ResizeObserver

60-second setup

Generic list

import { VirtualList } from "react-anchorlist"

<VirtualList
  data={tickets}
  computeItemKey={(_, item) => item.id}
  itemContent={(_, item) => <TicketRow ticket={item} />}
  onEndReached={loadMore}
  style={{ height: "100%" }}
/>

Chat list (recommended pattern)

import { useState } from "react"
import { ChatVirtualList } from "react-anchorlist"
import type { ChatScrollModifier } from "react-anchorlist"

const [scrollModifier, setScrollModifier] = useState<ChatScrollModifier | null>(null)

<ChatVirtualList
  data={messages}
  computeItemKey={(_, item) => item._id}
  itemContent={(_, item) => <Message data={item} />}
  scrollModifier={scrollModifier}
  followOutput="auto"
  onStartReached={async () => {
    // 1) tell the list to preserve anchor
    setScrollModifier({ id: `prepend-${Date.now()}`, type: "prepend" })
    // 2) prepend older messages in your state
    await loadOlderMessages()
  }}
  onAtBottomChange={setIsAtBottom}
  style={{ height: "100%" }}
/>

Core concept (important)

When data changes, control scroll behavior with scrollModifier:

type ChatScrollModifier =
  | { id: string | number; type: "prepend" }
  | { id: string | number; type: "append"; behavior?: "auto" | "smooth"; ifAtBottomOnly?: boolean }
  | { id: string | number; type: "items-change" }
  | { id: string | number; type: "jump-to-key"; key: string | number; align?: "start" | "center" | "end"; behavior?: ScrollBehavior }
  • id must be unique for each command.
  • prepend keeps viewport position stable while older messages are added on top.
  • append can auto-scroll to bottom.
  • jump-to-key scrolls to one specific item.

API quick reference

Exports

import {
  ChatVirtualList,
  VirtualList,
  useChatVirtualizer,
  usePagination,
} from "react-anchorlist"

ChatVirtualList most-used props

  • data, itemContent, computeItemKey (required)
  • scrollModifier (ChatScrollModifier | null)
  • followOutput ("auto" | "smooth" | false, default: "auto")
  • onStartReached, onEndReached
  • startReachedThreshold and endReachedThreshold (default: 300)
  • onAtBottomChange
  • estimatedItemSize (default: 80)
  • overscan (default: 20)

VirtualList most-used props

  • data, itemContent, computeItemKey (required)
  • onEndReached
  • endReachedThreshold (default: 300)
  • estimatedItemSize (default: 60)
  • overscan (default: 20)

ChatVirtualList ref handle

listRef.current?.scrollToBottom()
listRef.current?.scrollToIndex(42, { align: "center", behavior: "smooth" })
listRef.current?.scrollToKey("msg-123", { align: "center" })
listRef.current?.getScrollTop()
listRef.current?.isAtBottom()

usePagination hook (optional helper)

import { useEffect } from "react"
import { usePagination, ChatVirtualList } from "react-anchorlist"

const { items, hasPrevPage, loadPrevPage, loadingMore, refresh } = usePagination({
  fetcher: async (page) => {
    const res = await api.get(`/messages?page=${page}&per_page=50`)
    return {
      data: res.messages,
      hasNextPage: res.pagination.current_page < res.pagination.last_page,
      hasPrevPage: res.pagination.current_page > 1,
      currentPage: res.pagination.current_page,
    }
  },
  direction: "prepend",
  getKey: (msg) => msg._id,
})

useEffect(() => {
  refresh() // load initial page
}, [refresh])

<ChatVirtualList
  data={items}
  computeItemKey={(_, item) => item._id}
  itemContent={(_, item) => <Message data={item} />}
  onStartReached={hasPrevPage ? loadPrevPage : undefined}
  components={{
    Header: () => (loadingMore ? <Spinner /> : null),
  }}
/>

Best practices

  • Always use stable keys in computeItemKey.
  • Keep itemContent lightweight.
  • Start with a realistic estimatedItemSize.
  • Keep overscan low unless you need smoother very fast scrolling.
  • Prefer scrollModifier over deprecated APIs (prepareAnchor, scrollToMessageKey).

Internals (simple)

  • OffsetMap: stores cumulative offsets per item
  • Anchor snapshot: keeps visual position stable on prepend
  • Per-item ResizeObserver: updates real row heights
  • Binary search: quickly finds visible range

Keywords and discoverability

If your goal is npm discovery, keywords belong in package.json (not only in README text).

Suggested scope for this lib:

  • react
  • virtual-list
  • virtualization
  • virtual-scroll
  • chat
  • infinite-scroll
  • scroll-anchor

Copy-paste AI prompt

Use this prompt in ChatGPT/Claude/Cursor/GitHub Copilot Chat:

You are a senior React engineer. Integrate the npm library `react-anchorlist` into my app.

Context:
- Stack: [React version + framework]
- Data type: [message/ticket/feed item shape]
- Item unique key: [id field]
- List container height strategy: [fixed/flex/full-screen]

Goal:
Implement a production-ready virtualized list with smooth scrolling and correct pagination behavior.

Requirements:
1) Use `ChatVirtualList` for chat-like UX (prepend older items at top).
2) Use stable `computeItemKey`.
3) Use `scrollModifier` commands correctly:
   - before loading older items: `{ id: uniqueId, type: "prepend" }`
   - when appending new realtime items: use append/items-change behavior when appropriate
   - use `jump-to-key` for "scroll to message"
4) Keep `followOutput="auto"` and expose `onAtBottomChange`.
5) Wire `onStartReached` and/or `onEndReached` to my pagination functions.
6) Add proper TypeScript types.
7) Include minimal CSS/container setup so scrolling works (`height` + `overflow`).
8) Avoid deprecated APIs (`prepareAnchor`, `scrollToMessageKey`) unless migration support is explicitly requested.

Deliverables:
- Full component code ready to paste.
- State management for `scrollModifier`.
- Example handlers: `loadOlderMessages`, `loadNewerMessages`.
- Brief explanation of why the scroll stays stable on prepend.
- Optional: a second example using `VirtualList` for non-chat pages.

Project data to use:
- Messages state variable: [name here]
- Pagination function names: [names here]
- Message row component name: [name here]

Return clean, runnable code with no placeholders left.

License

MIT