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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-directory-view

v2.0.1

Published

Directory tree component made for React

Readme

React Directory View

You no longer need to write your recursion yourself. Just import the Tree component and supply treeData and treeMap props.

Build Status

How to use

Import the Tree Component, and specify treeMap and treeData props.

const App = () => (
  <Tree
    treeData={treeData}
    treeMap={treeMapping}
  />
);

The treeMap prop is just an object containing the configuration for your tree. An example below:

const treeMapping = {
  /**
    * {string=}
    * recursiveKey is the key on your object tree which
    * the tree structure recursively maps over. By
    * default it looks for 'children'.
    */
  recursiveKey: 'children',
  /**
    * {string}
    * The React key given to each JSX node for dom comparison.
    */
  nodeKey: 'id',
  /**
    * {string=}
    * If a component isn't given to treeMapping, then
    * the 'childToRender' is rendered for each node in the tree.
    * This relates to the treeData you're passing to the Tree component.
    */
  childToRender: 'path',
};

A basic example could like below:

import React, { Fragment } from 'react';
import Tree from './components/Tree';
import ExampleComponent from './components/ExampleComponent';

const treeMapping = {
  recursiveKey: 'children', // recursiveKey is set to 'children' by default
  nodeKey: 'id',
  childToRender: 'path',
};

const treeData = [
  {
    path: 'this',
    id: 1,
    children: [
      {
        path: 'is',
        id: 2,
        children: [
          {
            path: 'a',
            id: 3,
            children: [
              {
                path: 'few',
                id: 4,
                children: [
                  {
                    path: 'deep',
                    id: 5,
                    children: [],
                  },
                ],
              },
            ],
          },
        ],
      },
    ],
  },
];

const App = () => (
  <Fragment>
    <Tree
      treeData={treeData}
      treeMap={treeMapping}
    />
  </Fragment>
);

This will render a tree that looks like:

> This
  > Is
    > A
      > Few
        Deep

Props

| Prop | Default | required | Description | :--------|:--------:|:----------:|:------------ treeData | Empty array | Yes | The data to recursively map over treeMap | Empty object | Yes | Describes the nodes / keys to use when mapping over each child array useCheckbox | False | No | Wether to use checkboxes or not checkboxStyles | Empty object | No | Style object used to add or override checkbox styles arrowStyles | empty object | No | Style object used to add or override arrow styles Component | None | No | A component to render for each node in the object tree. Receives all props from the treeNode. paddingLeft | 15px | No | The amount of padding to add for each child onContract | noOp | No | Callback to be invoked every time a child node is collapsed onExpand | noOp | No | Callback to be invoked every time a child node is expanded