React Tree Component (Legacy)

5.13.1 · renamed · verified Sun Apr 19

rc-tree is a foundational React UI component that provided a highly customizable and performant tree view. Its purpose was to display hierarchical data with features such as node expansion, selection, checking, dragging, and asynchronous data loading. The last stable version under the `rc-tree` package name is 5.13.1. Development on this package has ceased under this name, as it has been officially renamed and migrated to `@rc-component/tree` starting from version `@rc-component/tree@1.2.2`. While `rc-tree` offered robust capabilities like custom node rendering, virtualized lists for large datasets (in later versions before the rename), and broad browser support (including IE9+), users are strongly advised to migrate to the actively maintained `@rc-component/tree` for ongoing updates, bug fixes, and new features. The original `rc-tree` package itself does not have a defined release cadence anymore due to its renamed status.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic interactive tree component using `rc-tree` with checkable nodes, controlled expansion, checking, and selection states. It includes the necessary CSS import and a minimal `treeData` structure.

import React, { useState } => from 'react';
import Tree from 'rc-tree';
import 'rc-tree/assets/index.css';

const treeData = [
  {
    key: '0-0',
    title: 'Parent Node 1',
    children: [
      { key: '0-0-0', title: 'Child Node 1-1' },
      { key: '0-0-1', title: 'Child Node 1-2' },
    ],
  },
  {
    key: '0-1',
    title: 'Parent Node 2',
    children: [
      { key: '0-1-0', title: 'Child Node 2-1' },
      { key: '0-1-1', title: 'Child Node 2-2' },
    ],
  },
];

const MyTreeComponent = () => {
  const [expandedKeys, setExpandedKeys] = useState([]);
  const [checkedKeys, setCheckedKeys] = useState([]);
  const [selectedKeys, setSelectedKeys] = useState([]);

  const onExpand = (keys) => {
    console.log('onExpand', keys);
    setExpandedKeys(keys);
  };

  const onCheck = (keys, info) => {
    console.log('onCheck', keys, info);
    setCheckedKeys(keys);
  };

  const onSelect = (keys, info) => {
    console.log('onSelect', keys, info);
    setSelectedKeys(keys);
  };

  return (
    <div style={{ padding: '20px' }}>
      <h2>Basic rc-tree Example</h2>
      <Tree
        checkable
        defaultExpandAll
        onExpand={onExpand}
        expandedKeys={expandedKeys}
        onCheck={onCheck}
        checkedKeys={checkedKeys}
        onSelect={onSelect}
        selectedKeys={selectedKeys}
        treeData={treeData}
      />
    </div>
  );
};

export default MyTreeComponent;

view raw JSON →