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

use-selectable

v1.0.16

Published

React hook for item selection

Downloads

12

Readme

use-selectable

A lightweight React hook for managing item selection states in lists, tables, or any collection of data. Easily toggle items, select all, clear selections, and retrieve selected items.

Features: Toggle single or all items, check if an item is selected, clear selections, get selected items and total count, zero dependencies (except React).

Installation:

npm install use-selectable

or with Yarn:

yarn add use-selectable

Usage:

import { useSelectable } from "use-selectable";

interface User {
  id: number;
  name: string;
}

const users: User[] = [
  { id: 1, name: "alex" },
  { id: 2, name: "alan" },
  { id: 3, name: "nunes" },
];

function App() {
  const {
    selected,
    isAllSelected,
    toggleItem,
    toggleAll,
    clear,
    totalSelected,
    isSelected,
  } = useSelectable(users, "id" /* default */);

  return (
    <div>
      <button onClick={toggleAll}>
        {isAllSelected ? "Deselect All" : "Select All"}
      </button>
      <button onClick={clear}>Clear</button>

      <ul>
        {users.map((user) => (
          <li key={user.id}>
            <label>
              <input
                type="checkbox"
                checked={isSelected(user.id)}
                onChange={() => toggleItem(user.id)}
              />
              {user.name}
            </label>
          </li>
        ))}
      </ul>

      <p>Total selected: {totalSelected}</p>
      <pre>{JSON.stringify(selected, null, 2)}</pre>
    </div>
  );
}

export default App;

API:

useSelectable<T, K extends keyof T>(data: T[], key?: K)

  • data: T[] (required) → Array of items to manage selection for.
  • key: K (default 'id') → The property of each item used as unique identifier.

Returns an object with:

  • selected: T[] → Array of currently selected items (based on key).
  • isAllSelected: boolean → True if all items are selected.
  • totalSelected: number → Number of selected items.
  • toggleItem(id: T[K]) → Toggle selection for an item by its id.
  • toggleAll() → Select all or clear all depending on current state.
  • isSelected(id: T[K]) → Check if an item is selected.
  • clear() → Clear all selections.
  • setSelectItems(ids: T[K][] | (selection: T[K][]) => T[K][]) → Manually set selection by array of ids or by updater function.

Notes: The hook automatically removes selections for items no longer present in data. Works with any property as the unique identifier, not just id.

Roadmap / Future Plans

  • Default Selected Items: Allow passing an array of default selected IDs when initializing the hook. This will enable pre-selection of items without extra calls to setSelectItems.

  • Core + Adapters Architecture: Similar to React Table’s approach, a future version of this library may separate the pure selection logic into a standalone package (e.g. @use-selectable/core) and keep the React hook as an adapter (@use-selectable/react).
    This will make the selection logic framework-agnostic, easier to test, and allow adapters for other frameworks such as Vue or Svelte in the future.

  • Improved Testing: Add unit and integration tests for both the core logic and the React hook using modern testing tools.

These changes are planned for a future release and may involve a major version bump if they introduce breaking changes.

More

Try other hooks