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-custom-tree

v3.0.1

Published

Fully customizable tree UI component for React with recursive rendering

Readme

React Custom Tree

npm version License: ISC

A fully customizable, recursive tree component for React with support for custom parent and child components.

🌐 Live Demo

View Live Demo →

Check out the interactive demo to see the component in action with various configurations and examples!

✨ Features

  • 🎨 Fully Customizable - Bring your own components for parents and children
  • 🔄 Recursive Rendering - Handles deeply nested tree structures
  • Lightweight - Minimal dependencies
  • 🎯 TypeScript Ready - Written with modern React patterns
  • 📦 Easy to Use - Simple API with sensible defaults
  • 🎭 Flexible Styling - Control margins and layout
  • 🔌 Event Handling - Built-in click handlers for child nodes

📦 Installation

npm install react-custom-tree

or

yarn add react-custom-tree

🚀 Quick Start

import React from 'react';
import Tree from 'react-custom-tree';

const data = [
  {
    id: 1,
    name: 'Parent 1',
    child: [
      {
        id: 2,
        name: 'Child 1'
      },
      {
        id: 3,
        name: 'Child 2'
      }
    ]
  }
];

function App() {
  return (
    <Tree
      data={data}
      onChidClick={(child) => console.log('Clicked:', child)}
    />
  );
}

export default App;

📖 API Reference

Props

| Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | data | Array | [] | ✅ | Array of tree node objects | | onChidClick | Function | undefined | ❌ | Callback fired when a child node is clicked | | childComponent | Component | Built-in | ❌ | Custom component for rendering child nodes | | parentComponent | Component | Built-in | ❌ | Custom component for rendering parent nodes | | isDefaultOpen | Boolean | false | ❌ | Whether parent nodes are expanded by default | | noLeftMargin | Boolean | false | ❌ | Remove left margin from tree nodes |

Data Structure

Each node in the data array should follow this structure:

{
  id: number | string,        // Unique identifier (required)
  name: string,               // Display name (required)
  child: Array,               // Array of child nodes (optional)
  // ... any other custom properties
}

💡 Examples

Basic Usage

import React from 'react';
import Tree from 'react-custom-tree';
import data from './data.json';

function BasicExample() {
  return (
    <Tree
      data={data}
      onChidClick={(child) => console.log(child)}
    />
  );
}

Default Open State

function DefaultOpenExample() {
  return (
    <Tree
      data={data}
      isDefaultOpen={true}
      onChidClick={(child) => console.log(child)}
    />
  );
}

Custom Components

import React from 'react';
import Tree from 'react-custom-tree';
import data from './data.json';

// Custom child component
const CustomChild = (props) => (
  <div className="custom-child">
    📄 {props.name}
  </div>
);

// Custom parent component
const CustomParent = (props) => (
  <div className="custom-parent">
    <span className="icon">
      {props.open ? '📂' : '📁'}
    </span>
    <span className="name">{props.name}</span>
  </div>
);

function CustomExample() {
  return (
    <Tree
      data={data}
      onChidClick={(child) => console.log(child)}
      parentComponent={CustomParent}
      childComponent={CustomChild}
    />
  );
}

With Font Awesome Icons

const CustomParent = (props) => (
  <div className="custom-parent">
    <span className="icon">
      {props.open ? (
        <i className="fa fa-caret-down" aria-hidden="true"></i>
      ) : (
        <i className="fa fa-caret-right" aria-hidden="true"></i>
      )}
    </span>
    {props.name}
  </div>
);

function FontAwesomeExample() {
  return (
    <Tree
      data={data}
      parentComponent={CustomParent}
      onChidClick={(child) => console.log(child)}
    />
  );
}

Without Left Margin

function NoMarginExample() {
  return (
    <Tree
      data={data}
      noLeftMargin={true}
      onChidClick={(child) => console.log(child)}
    />
  );
}

🎨 Styling

The component comes with minimal default styles. You can override them by targeting these CSS classes:

.tree-margin-left-15 {
  margin-left: 15px;
}

.tree-parent-component {
  cursor: pointer;
  padding: 5px;
}

.tree-child-component {
  cursor: pointer;
  padding: 5px;
}

📝 Sample Data Structure

[
  {
    "id": 1,
    "name": "Parent 1",
    "child": [
      {
        "id": 2,
        "name": "Parent 1.1",
        "child": [
          {
            "id": 3,
            "name": "Child 1"
          }
        ]
      },
      {
        "id": 4,
        "name": "Parent 1.2",
        "child": [
          {
            "id": 5,
            "name": "Child 2"
          },
          {
            "id": 6,
            "name": "Child 3"
          }
        ]
      }
    ]
  },
  {
    "id": 7,
    "name": "Parent 2",
    "child": []
  }
]

🌐 Live Demo

Check out the live demo to see the component in action with various configurations.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the ISC License.

👨‍💻 Author

Sojin Antony

🙏 Acknowledgments

Special thanks to Viswanath Lekshmanan for contributions and support.

📊 Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

⚙️ Requirements

  • React >= 16.8.0 (hooks support required)
  • React-DOM >= 16.8.0

Note: While the package works with React 16.8.0+, we recommend using React 18+ for optimal performance and latest features.

🔄 Changelog

Version 2.0.0

  • ✨ Modernized with React functional components and hooks
  • 🔄 Maintained backward compatibility with React 16.8.0+
  • 📚 Enhanced documentation with comprehensive examples
  • 🎨 Improved demo with modern UI and more examples
  • 🚀 Added GitHub Actions for automated deployment
  • 🎯 Better TypeScript support and modern patterns

Version 1.0.5

  • Initial stable release
  • Basic tree functionality
  • Custom component support

Made with ❤️ by Sojin Antony