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

@mshafiqyajid/react-tree

v0.3.0

Published

Headless tree view hook and styled component for React. Expand/collapse, selection, async children, keyboard navigation. Zero dependencies, fully typed.

Readme

@mshafiqyajid/react-tree

Headless tree view hook and styled component for React. Expand/collapse, single or multi-select, async children loading, full keyboard navigation, indent guides. Zero dependencies, fully typed.

Full docs →

Install

npm install @mshafiqyajid/react-tree

Quick start (styled)

import { TreeStyled } from "@mshafiqyajid/react-tree/styled";
import "@mshafiqyajid/react-tree/styles.css";

const items = [
  {
    id: "src",
    label: "src",
    children: [
      { id: "components", label: "components", children: [
        { id: "Button.tsx", label: "Button.tsx" },
      ]},
      { id: "index.ts", label: "index.ts" },
    ],
  },
  { id: "package.json", label: "package.json" },
];

<TreeStyled
  items={items}
  defaultExpandedIds={["src"]}
  onSelectedChange={(id) => console.log(id)}
/>

Async children

<TreeStyled
  items={[{ id: "root", label: "root", children: undefined }]}
  loadChildren={async (node) => {
    const res = await fetch(`/api/children/${node.id}`);
    return res.json();
  }}
/>

When a node has children: undefined AND a loadChildren is set, expanding it triggers the loader. The chevron is replaced with a spinner during the request.

Headless

import { useTree } from "@mshafiqyajid/react-tree";

const tree = useTree({ items, defaultExpandedIds: ["src"] });

return (
  <ul {...tree.getRootProps()}>
    {tree.visibleNodes.map(({ node, depth, hasChildren }) => (
      <li key={node.id} {...tree.getNodeProps(node, depth)} style={{ paddingLeft: depth * 18 }}>
        {hasChildren && (
          <button {...tree.getToggleProps(node)}>
            {tree.isExpanded(node.id) ? "▾" : "▸"}
          </button>
        )}
        {node.label}
      </li>
    ))}
  </ul>
);

Keyboard navigation

| Key | Action | |-----|--------| | / | Move focus between visible nodes | | | Expand collapsed parent / move to first child | | | Collapse expanded parent / move to parent | | Home / End | Jump to first / last visible node | | Enter / Space | Select the focused node |

Features

  • Expand / collapse — controlled (expandedIds + onExpandedChange) or uncontrolled (defaultExpandedIds).
  • Selection — single (default) or selectionMode: "multiple". Both controlled and uncontrolled.
  • Async childrenloadChildren(node) => Promise<TreeNode[]> fires on first expand of nodes with children: undefined.
  • Indent guides — vertical 1px lines drawn between nesting levels (toggle with showGuides).
  • A11y — full ARIA tree pattern (role="tree" / treeitem, aria-expanded, aria-selected, aria-level).

Props (styled)

| Prop | Type | Default | Description | |------|------|---------|-------------| | items | TreeNode[] | — | Required | | defaultExpandedIds / expandedIds / onExpandedChange | controlled state | — | Expanded ids | | defaultSelectedId / selectedId / onSelectedChange | controlled state | — | Single-selected id | | selectionMode | "single" \| "multiple" | "single" | — | | selectedIds / onSelectedIdsChange | controlled ids | — | Multi-selection (when selectionMode === "multiple") | | loadChildren | (node) => Promise<TreeNode[]> | — | Async children loader | | size | "sm" \| "md" \| "lg" | "md" | Row size | | tone | "neutral" \| "primary" | "primary" | Accent | | showGuides | boolean | true | Indent guide lines | | searchQuery | string | "" | Filter visible nodes by case-insensitive label match. Auto-expands matching ancestors. | | highlightMatches | boolean | true | Bolden matched query characters in labels | | checkboxes | boolean | false | Render a checkbox per node alongside the label | | renderLabel | (node, depth) => ReactNode | — | Custom label renderer | | renderBadge | (node) => ReactNode | — | Slot rendered after the label (e.g., count, status) | | emptyState | ReactNode | auto | Shown when no nodes match the search |

TreeNode

| Field | Type | Description | |-------|------|-------------| | id | string | Required, unique | | label | ReactNode | Required | | children | TreeNode[] \| undefined | undefined = leaf or async-loadable. [] = empty branch. | | icon | ReactNode? | Left-side icon | | disabled | boolean? | Greyed out, can't toggle/select | | data | T? | Free-form payload |

License

MIT