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-virtual-dropdown

v1.2.8

Published

The React Virtual Dropdown is a virtual scrolling-based selector component designed to optimize data loading and rendering. Instead of loading all data at once, it loads a specific number of items and fetches new data as the user scrolls.

Downloads

7

Readme

React Virtual Dropdown Component

The VirtualSelector is a virtual scrolling-based selector component designed to optimize data loading and rendering. Instead of loading all data at once, it loads a specific number of items and fetches new data as the user scrolls.

Props

  • fetchData (function) - An asynchronous function that fetches data based on startIndex and limit, returning items and totalCount.
  • height (number) - The maximum height of the component (in pixels).
  • rowHeight (number) - The height of each item, used for virtual scrolling calculations.
  • placeholder (string) - Placeholder text displayed in the dropdown.
  • selectedData (string | object) - Default value for the selected item.
  • callBack (function) - A callback function triggered when a user selects an item, returning the selected item's data.

How It Works?

  • Data Fetching: Fetches new data dynamically based on scrolling using the fetchData function.
  • Optimized Rendering: Renders only visible items based on rowHeight to improve performance.
  • User Interaction: Calls the callBack function when a user selects an item, returning the selected data.

Use Cases

  • Dropdown lists with a large number of items.
  • Optimized data loading to enhance user experience.
  • Fetching paginated data from a server dynamically.

Getting started

Install react-virtual-dropdown using npm.

npm i react-virtual-dropdown

Setup

import { SelectItem, SelectorRequest, VirtualSelector } from "react-virtual-dropdown";
import { useCallback, useEffect, useState } from "react";

export default function Home() {
  const [selectedData, setSelectedData] = useState<string>('');
  const fetchData = useCallback(async (request: SelectorRequest) => {
    try {
      const params = new URLSearchParams({
            skip: request.startIndex.toString(),
            limit: request.limit.toString(),
            sortColumn: 'name',
            sortOrder: '',
            searchKey: request.searchKey ?? '',
        });
      const url = `https://your_url/comments?${params}`;
      const response = await fetch(url);
      if(!response.ok) throw new Error();
      const data = await response.json();
      const itemData = data.map(({ id, email }: { id: number, email: number }) => ({
        id: id.toString(), 
        name: email.toString() 
      }));
  
      const countUrl = `http://your_url/count?searchKey=${request.searchKey}`;
      const countResponse = await fetch(countUrl);
      if(!countResponse.ok) throw new Error();
      const count = await countResponse.json();
      return {
        items: itemData,
        totalCount: count,
      };
    } catch (error) {
      console.error("Error fetching data:", error);
      return {
        items: [],
        totalCount: 0,
      };
    }
  }, []);

  const getValue = (data: SelectItem) => {
    console.log(data.id, data.name);
  };

  const getSetData = async () => {
    const countUrl = `http://your_url/your-data-id`;
      const countResponse = await fetch(countUrl);
      if(!countResponse.ok) throw new Error();
      const data = await countResponse.json();
      setSelectedData(data);
  };

  useEffect(() => {
      getSetData()
  }, [])

  return (
    <div className={styles.page}>
      <h1>Alhadmulilah</h1>
      <div style={{width: "500px"}}>
      <VirtualSelector
          fetchData={fetchData}
          height={400}
          rowHeight={35}
          placeholder="Select Dropdown"
          selectedData={selectedData}
          callBack={getValue} />
      </div>
    </div>
  );
}

Now you're ready to start using the components.

Output

Dependencies

react-virtual-dropdown has very few dependencies and most are managed by NPM automatically.

Supported Browsers

react-virtual-dropdown aims to support all evergreen browsers and recent mobile browsers for iOS and Android. IE 9+ is also supported (although IE 9 will require some user-defined, custom CSS since flexbox layout is not supported).