react-treebeard vs react-sortable-tree
React Tree View Libraries Comparison
1 Year
react-treebeardreact-sortable-treeSimilar Packages:
What's React Tree View Libraries?

React tree view libraries are specialized components designed to display hierarchical data structures in a user-friendly format. They enable developers to create interactive tree views that allow users to expand and collapse nodes, facilitating better navigation and organization of complex data. These libraries often come with features like drag-and-drop functionality, customizable styles, and event handling, making them essential for applications that require a structured representation of data, such as file explorers, organizational charts, or nested categories.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-treebeard63,0971,689-726 years agoMIT
react-sortable-tree58,7294,961-3445 years agoMIT
Feature Comparison: react-treebeard vs react-sortable-tree

Interactivity

  • react-treebeard:

    react-treebeard provides basic interactivity, such as expanding and collapsing nodes, but lacks built-in drag-and-drop functionality. This makes it suitable for applications where the tree structure is primarily for display rather than manipulation.

  • react-sortable-tree:

    react-sortable-tree offers extensive interactivity, allowing users to drag and drop nodes to rearrange them within the tree structure. This feature is crucial for applications that require dynamic data manipulation, providing a responsive user experience that enhances usability.

Customization

  • react-treebeard:

    react-treebeard also offers customization options, but they are more limited compared to react-sortable-tree. It allows for custom node rendering and basic styling, making it easier to integrate into existing designs without extensive modifications.

  • react-sortable-tree:

    react-sortable-tree is highly customizable, allowing developers to define their own node rendering and styling. This flexibility enables the creation of unique tree views that can match the application's design language and user experience requirements.

Performance

  • react-treebeard:

    react-treebeard is lightweight and performs well with smaller datasets. However, as the size of the tree grows, performance may become a concern, especially if many nodes are rendered simultaneously without optimization strategies.

  • react-sortable-tree:

    react-sortable-tree is optimized for performance with large datasets, employing techniques like virtualization to ensure smooth rendering and interaction. This is particularly beneficial for applications that handle extensive hierarchical data and require quick response times.

Learning Curve

  • react-treebeard:

    react-treebeard is relatively easy to learn and implement, making it accessible for developers who need a simple tree view without complex functionalities. Its straightforward API allows for quick integration into projects.

  • react-sortable-tree:

    react-sortable-tree has a moderate learning curve due to its rich feature set and interactivity options. Developers may need to invest time in understanding its API and customization capabilities to fully leverage its potential.

Use Cases

  • react-treebeard:

    react-treebeard is best suited for applications that need to display static hierarchical data, such as organizational charts, category trees, or any scenario where user interaction is minimal.

  • react-sortable-tree:

    react-sortable-tree is ideal for applications that require user-driven data organization, such as project management tools, file explorers, and any scenario where users need to rearrange items dynamically.

How to Choose: react-treebeard vs react-sortable-tree
  • react-treebeard:

    Choose react-treebeard if you prefer a lightweight and straightforward tree component that emphasizes simplicity and performance. It is well-suited for applications where the tree structure is more static and does not require extensive interactivity. Its ease of use and customizable rendering make it a good choice for displaying hierarchical data without complex interactions.

  • react-sortable-tree:

    Choose react-sortable-tree if you need a highly interactive tree view with drag-and-drop capabilities. It is ideal for applications that require users to rearrange items easily, such as task management tools or file organization systems. Its focus on sortable trees makes it a great choice for dynamic data manipulation.

README for react-treebeard

react-treebeard

Build Status Coverage Status

React Tree View Component. Data-Driven, Fast, Efficient and Customisable.

Install

npm install react-treebeard --save

Example

An online example from the /example directory can be found here: Here

Quick Start

import React, {PureComponent} from 'react';
import ReactDOM from 'react-dom';
import {Treebeard} from 'react-treebeard';

const data = {
    name: 'root',
    toggled: true,
    children: [
        {
            name: 'parent',
            children: [
                { name: 'child1' },
                { name: 'child2' }
            ]
        },
        {
            name: 'loading parent',
            loading: true,
            children: []
        },
        {
            name: 'parent',
            children: [
                {
                    name: 'nested parent',
                    children: [
                        { name: 'nested child 1' },
                        { name: 'nested child 2' }
                    ]
                }
            ]
        }
    ]
};

class TreeExample extends PureComponent {
    constructor(props){
        super(props);
        this.state = {data};
    }
    
    onToggle(node, toggled){
        const {cursor, data} = this.state;
        if (cursor) {
            this.setState(() => ({cursor, active: false}));
        }
        node.active = true;
        if (node.children) { 
            node.toggled = toggled; 
        }
        this.setState(() => ({cursor: node, data: Object.assign({}, data)}));
    }
    
    render(){
        const {data} = this.state;
        return (
            <Treebeard
                data={data}
                onToggle={this.onToggle}
            />
        );
    }
}

const content = document.getElementById('content');
ReactDOM.render(<TreeExample/>, content);

If you use react-hooks you should do something like this:

import React, {useState} from 'react';
const TreeExample = () => {
    const [data, setData] = useState(data);
    const [cursor, setCursor] = useState(false);
    
    const onToggle = (node, toggled) => {
        if (cursor) {
            cursor.active = false;
        }
        node.active = true;
        if (node.children) {
            node.toggled = toggled;
        }
        setCursor(node);
        setData(Object.assign({}, data))
    }
    
    return (
       <Treebeard data={data} onToggle={onToggle}/>
    )
}

const content = document.getElementById('content');
ReactDOM.render(<TreeExample/>, content);

Prop Values

data

PropTypes.oneOfType([PropTypes.object,PropTypes.array]).isRequired

Data that drives the tree view. State-driven effects can be built by manipulating the attributes in this object. Also supports an array for multiple nodes at the root level. An example can be found in example/data.js

onToggle

PropTypes.func

Callback function when a node is toggled / clicked. Passes 2 attributes: the data node and it's toggled boolean state.

style

PropTypes.object

Sets the treeview styling. Defaults to src/themes/default.

animations

PropTypes.oneOfType([PropTypes.object, PropTypes.bool])

Sets the treeview animations. Set to false if you want to turn off animations. See velocity-react for more details. Defaults to src/themes/animations.

decorators

PropTypes.object

Decorates the treeview. Here you can use your own Container, Header, Toggle and Loading components. Defaults to src/decorators. See example below:

const decorators = {
    Loading: (props) => {
        return (
            <div style={props.style}>
                loading...
            </div>
        );
    },
    Toggle: (props) => {
        return (
            <div style={props.style}>
                <svg height={props.height} width={props.width}>
                    // Vector Toggle Here
                </svg>
            </div>
        );
    },
    Header: (props) => {
        return (
            <div style={props.style}>
                {props.node.name}
            </div>
        );
    },
    Container: (props) => {
        return (
            <div onClick={this.props.onClick}>
                // Hide Toggle When Terminal Here
                <this.props.decorators.Toggle/>
                <this.props.decorators.Header/>
            </div>
        );
    }
};

<Treebeard data={...} decorators={decorators}/>

Data Attributes

{
    id: '[optional] string',
    name: 'string',
    children: '[optional] array',
    toggled: '[optional] boolean',
    active: '[optional] boolean',
    loading: '[optional] boolean',
    decorators: '[optional] object',
    animations: '[optional] object'
},

id

The component key. If not defined, an auto-generated index is used.

name

The name prop passed into the Header component.

children

The children attached to the node. This value populates the subtree at the specific node. Each child is built from the same basic data structure. Tip: Make this an empty array, if you want to asynchronously load a potential parent.

toggled

Toggled flag. Sets the visibility of a node's children. It also sets the state for the toggle decorator.

active

Active flag. If active, the node will be highlighted. The highlight is derived from the node.activeLink style object in the theme.

loading

Loading flag. It will populate the treeview with the loading component. Useful when asynchronously pulling the data into the treeview.

decorators / animations

Attach specific decorators / animations to a node. Provides the low level functionality to create visuals on a node-by-node basis. These structures are the same as the top level props, described above.