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

infinite-level-tree

v1.0.9

Published

- โšก **Dynamic and Scalable Tree Rendering**: Efficiently handles large, hierarchical datasets with support for dynamic node loading, ideal for applications like file explorers or organizational charts. - ๐Ÿ› ๏ธ **React-Friendly API**: Seamlessly integrates

Readme

๐Ÿš€ Infinite Level Tree

๐Ÿ“ฆ Owned by: Vu Tri Khoa (GitLab)

โœจ Features

  • โšก Dynamic and Scalable Tree Rendering: Efficiently handles large, hierarchical datasets with support for dynamic node loading, ideal for applications like file explorers or organizational charts.
  • ๐Ÿ› ๏ธ React-Friendly API: Seamlessly integrates with React using the TreeView component and useTreeNode hook, offering intuitive setup and customizable node rendering.
  • โœ… Interactive Node Selection: Supports checkable nodes with bulk check/uncheck functionality, enabling easy management of selected items across the tree.
  • ๐Ÿ”„ Flexible Node Expansion: Provides programmatic control over node expansion and collapse, with customizable icons and styles for a tailored user experience.
  • ๐Ÿ”’ Secure and Reliable: Ensures safe data handling with automatic ID generation for nodes and secure event management, adhering to modern React best practices.

๐Ÿ“œ Installation

# Clone the repository
git clone https://github.com/khoavutri/infinite-level-tree.git

# Install dependencies
npm install

# Start the application
npm start

๐Ÿ“œ Demo

Explore the infinite-level-tree in action! The demo showcases a dynamic, hierarchical tree structure with features like node selection, drag-and-drop, and lazy loading of child nodes.

๐Ÿ“บ Live Demo: infinite-level-tree

๐Ÿ–ผ๏ธ Screenshot: Comming soon...

๐Ÿ“œ API

The infinite-level-tree library provides a powerful and flexible API for creating and managing hierarchical tree structures. Below is an overview of the key methods and configuration options.

Installation

Install via npm:

npm install infinite-level-tree

Basic Usage

Initialize a tree with a DOM element and data structure:

import { useEffect } from "react";
import { TreeView, useTreeNode } from "infinite-level-tree";
import data from "./test.json";

const MyTooltip = ({ data }: { data?: any }) => {
  return (
    <div style={{ margin: 0, padding: 0 }}>
      <h4>{data && data.name}</h4>
      <p>{data && data.describe}</p>
    </div>
  );
};

const App = () => {
  const tree = useTreeNode({ data, config: { left: 50 } });

  useEffect(() => {
    const unsubscribe = tree.onCheckedChange((x) => {
      console.log(x.generateCheckedTree());
    });

    return () => {
      unsubscribe();
    };
  }, []);

  return (
    <div style={{ height: "100%" }}>
      <TreeView treeNode={tree} popoverContent={MyTooltip} />
      <div style={{ display: "flex", gap: "8px", marginTop: "12px" }}>
        <button onClick={() => tree.checkAll()}>Check All</button>

        <button onClick={() => tree.unCheckAll()}>Uncheck All</button>

        <button onClick={() => tree.openAll()}>Open All</button>

        <button onClick={() => tree.closeAll()}>Close All</button>

        <button
          style={{ backgroundColor: "#3b82f6", color: "#fff" }}
          onClick={() => {
            const newData = tree.generateCheckedTree();
            console.log(newData);
          }}
        >
          Generate Data
        </button>
      </div>
    </div>
  );
};

export default App;

Configuration Options

The infinite-level-tree library leverages the useTreeNode hook and TreeView component to manage tree structures in React applications. Below are the key configuration options for the useTreeNode hook and TreeView component.

useTreeNode Hook Configuration

The useTreeNode hook processes tree data and provides state management for node selection and expansion. It accepts the following parameters:

  • data: (Object | Array | null) - The tree data structure. Each node should include properties like id, name, children (optional), and checked (optional). If id is missing, a UUID is automatically assigned.
  • mapper: (Mapper) - Customizes property names for the tree data. Defaults to:
    {
      id: 'id',
      name: 'name',
      children: 'children',
      checked: 'checked'
    }
    Example: { id: 'key', name: 'label', children: 'subnodes' } to map custom field names.
  • config: (Config) - Optional configuration object. Supports:
    • initalChecked: (Boolean) - If true, all leaf nodes are checked initially; if false, none are checked; if underfine, uses the checked property from the data.
    • initalOpen: (Boolean) - If true, all folders are expanded initially; if false, all folders are collapsed. Default is false.
    • left: (Number) - The indentation in pixels for each level of the tree. Default is 10.
    • disableOnlyFolder: (Boolean) โ€“ If false or not set, clicking on the folder name will select all items inside that folder and simultaneously deselect all items outside the folder. If true, this behavior is disabled.
    • disableOnlyItem: (Boolean) โ€“ If false or not set, clicking on the item name will select only that item and deselect all other items. If true, this behavior is disabled.

TreeView Component Props

The TreeView component renders the tree structure and supports customization for styling and behavior. It accepts the following props:

  • treeNode: (TreeNode) - The tree node object returned by useTreeNode, containing processed data and methods.
  • popoverContent: (any) โ€“ Optional content for a popover displayed when interacting with a node. (โš ๏ธFeature in development โ€“ use with caution)
  • folderIcon: (React.ReactNode) - Custom icon for folder nodes.
  • expandIcon: (React.ReactNode) - Custom icon for expanded nodes.
  • toggleIcon: (React.ReactNode) - Custom icon for toggling node expansion.
  • folderNameStyle: (React.CSSProperties) - Custom styles for folder names.
  • itemNameStyle: (React.CSSProperties) - Custom styles for item (leaf) names.
  • checkboxStyle: (React.CSSProperties) - Custom styles for checkboxes.
  • triggerPopoverStyle: (React.CSSProperties) - Styles for the popover trigger.
  • popoverStyle: (React.CSSProperties) - Styles for the popover container.
  • className: (String) - Additional CSS classes for the tree container, merged with default styles (styles.infiniteLevelTree).

Key Methods

The useTreeNode hook returns a TreeNode object with methods to manage the tree's state and behavior. Below are the key methods available:

  • getIdByFolder(data): Returns an array of IDs for all leaf nodes (nodes without children) in the provided data.
    • Parameters: data (tree data to traverse).
    • Returns: ID[] (array of node IDs).
  • checkAll(): Checks all leaf nodes by setting their IDs in the current state.
  • unCheckAll(): Unchecks all nodes by clearing the current state.
  • openAll(): Triggers expansion of all nodes by incrementing the triggerOpen state.
  • closeAll(): Collapses all nodes by incrementing the triggerOpen state.
  • generateCheckedTree(filterFields?): Generates a new tree with updated checked properties based on the current state.
    • Parameters: filterFields (optional array of field names to exclude from the output).
    • Returns: Processed tree data with updated checked properties.
  • onCheckedChange(callback): Subscribes to changes in the checked state.
    • Parameters: callback (function receiving the updated TreeNode).
    • Returns: A cleanup function to unsubscribe from the event.
  • setCurrent(ids): Manually sets the array of checked node IDs.
    • Parameters: ids (array of node IDs to mark as checked).

The TreeNode object also exposes:

  • originalData: The raw input data.
  • data: The processed tree data with assigned IDs.
  • mapper: The active mapper configuration.
  • config: The active config object.
  • current: Array of currently checked node IDs.
  • triggerOpen: State controlling node expansion.

Example: Dynamic Node Loading

The useTreeNode hook supports dynamic node loading by processing data asynchronously and updating the tree state. Below is an example demonstrating how to integrate useTreeNode with TreeView for a tree with dynamically loaded nodes.

import React, { useEffect } from "react";
import { TreeView, useTreeNode } from "infinite-level-tree";

const App = () => {
  const [data, setData] = React.useState({
    id: "root",
    name: "Root",
    checked: true,
    children: [],
  });

  const treeNode = useTreeNode({
    data,
    mapper: {
      id: "id",
      name: "name",
      children: "children",
      checked: "checked",
    },
    config: { initalChecked: false },
  });

  // Log checked nodes
  useEffect(() => {
    const unsubscribe = tree.onCheckedChange((x) => {
      console.log(x.generateCheckedTree());
    });

    return () => {
      unsubscribe();
    };
  }, []);

  return (
    <TreeView
      treeNode={treeNode}
      folderIcon={<span>๐Ÿ“</span>}
      expandIcon={<span>โžก๏ธ</span>}
      toggleIcon={<span>๐Ÿ”„</span>}
      folderNameStyle={{ fontWeight: "bold" }}
      itemNameStyle={{ color: "blue" }}
      checkboxStyle={{ marginRight: "5px" }}
      className="custom-tree"
    />
  );
};

export default App;

This example:

  • Uses useEffect to simulate fetching child nodes after a delay.
  • Renders the tree with custom icons and styles using the TreeView component.
  • Subscribes to checked state changes to log selected nodes.

For a complete API reference, see the GitHub repository.


๐Ÿ“ž Support

๐Ÿ’Œ Email: Reach out to me at [email protected]
๐Ÿ› GitHub Issues: Found a bug or have a suggestion? Open an issue here
๐Ÿ’ฌ Community Chat: Join the discussion on Facebook