{"id":18910036,"url":"https://github.com/cheton/react-infinite-tree","last_synced_at":"2025-07-24T16:33:00.389Z","repository":{"id":41487054,"uuid":"55903540","full_name":"cheton/react-infinite-tree","owner":"cheton","description":"The infinite-tree library for React.","archived":false,"fork":false,"pushed_at":"2019-10-04T06:07:23.000Z","size":6016,"stargazers_count":76,"open_issues_count":9,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-21T15:48:35.841Z","etag":null,"topics":["customizable","infinite-scroll","react","react-dom","server-side-rendering","tree"],"latest_commit_sha":null,"homepage":"http://cheton.github.io/react-infinite-tree/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cheton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":"cheton","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-04-10T14:26:57.000Z","updated_at":"2025-03-21T03:16:07.000Z","dependencies_parsed_at":"2022-09-05T01:31:02.354Z","dependency_job_id":null,"html_url":"https://github.com/cheton/react-infinite-tree","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/cheton/react-infinite-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freact-infinite-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freact-infinite-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freact-infinite-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freact-infinite-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheton","download_url":"https://codeload.github.com/cheton/react-infinite-tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freact-infinite-tree/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266871419,"owners_count":23998262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["customizable","infinite-scroll","react","react-dom","server-side-rendering","tree"],"created_at":"2024-11-08T09:39:07.489Z","updated_at":"2025-07-24T16:33:00.359Z","avatar_url":"https://github.com/cheton.png","language":"JavaScript","funding_links":["https://opencollective.com/cheton"],"categories":["React"],"sub_categories":["React Components"],"readme":"# react-infinite-tree [![build status](https://travis-ci.org/cheton/react-infinite-tree.svg?branch=master)](https://travis-ci.org/cheton/react-infinite-tree) [![Coverage Status](https://coveralls.io/repos/github/cheton/react-infinite-tree/badge.svg?branch=master)](https://coveralls.io/github/cheton/react-infinite-tree?branch=master)\n\n[![NPM](https://nodei.co/npm/react-infinite-tree.png?downloads=true\u0026stars=true)](https://www.npmjs.com/package/react-infinite-tree)\n\nThe [infinite-tree](https://github.com/cheton/infinite-tree) library for React.\n\nDemo: http://cheton.github.io/react-infinite-tree\n\n[![react-infinite-tree](https://raw.githubusercontent.com/cheton/react-infinite-tree/master/media/react-infinite-tree.gif)](http://cheton.github.io/react-infinite-tree)\n\n## Features\n* High performance infinite scroll with large data set\n* [Customizable renderer](https://github.com/cheton/react-infinite-tree#rendering-tree-nodes) to render the tree in any form\n* [Load nodes on demand](https://github.com/cheton/infinite-tree/wiki/Options#loadnodes)\n* Native HTML5 drag and drop API\n* A rich set of [APIs](https://github.com/cheton/react-infinite-tree#api)\n\n## Browser Support\n![Chrome](https://github.com/alrra/browser-logos/raw/master/src/chrome/chrome_48x48.png)\u003cbr\u003eChrome | ![Edge](https://github.com/alrra/browser-logos/raw/master/src/edge/edge_48x48.png)\u003cbr\u003eEdge | ![Firefox](https://github.com/alrra/browser-logos/raw/master/src/firefox/firefox_48x48.png)\u003cbr\u003eFirefox | ![IE](https://github.com/alrra/browser-logos/raw/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png)\u003cbr\u003eIE | ![Opera](https://github.com/alrra/browser-logos/raw/master/src/opera/opera_48x48.png)\u003cbr\u003eOpera | ![Safari](https://github.com/alrra/browser-logos/raw/master/src/safari/safari_48x48.png)\u003cbr\u003eSafari\n--- | --- | --- | --- | --- | --- |\n Yes | Yes | Yes| 9+ | Yes | Yes | \n\n## Installation\n```sh\nnpm install --save react-infinite-tree\n```\n\n## Usage\n\n### Tree Structure\n\nA tree structure can either be a node object or an array of node objects, and each node should have a unique `id`. Note that `id`, `state`, `children`, and `parent` are reserved keys for defining a node. See below for a basic tree structure:\n\n```js\n{\n    id: 'fruit',\n    name: 'Fruit',\n    children: [{\n        id: 'apple',\n        name: 'Apple'\n    }, {\n        id: 'banana',\n        name: 'Banana',\n        children: [{\n            id: 'cherry',\n            name: 'Cherry',\n            loadOnDemand: true\n        }]\n    }]\n}\n```\n\n### Rendering Tree Nodes\n\nYou can use `rowRenderer` or pass a child function for rendering tree nodes. The child function will be supplied with the following properties:\n\n* `tree` - https://github.com/cheton/infinite-tree/wiki/Functions:-Tree\n* `node` - https://github.com/cheton/infinite-tree/wiki/Functions:-Node\n\n\n```jsx\nimport React from 'react';\nimport InfiniteTree from 'react-infinite-tree';\n\nexport default (props) =\u003e (\n    \u003cInfiniteTree\n        width=\"100%\"\n        height={400}\n        rowHeight={30}\n        data={props.data}\n    \u003e\n    {({ node, tree }) =\u003e {\n        // Determine the toggle state\n        let toggleState = '';\n        const hasChildren = node.hasChildren();\n        if ((!hasChildren \u0026\u0026 node.loadOnDemand) || (hasChildren \u0026\u0026 !node.state.open)) {\n            toggleState = 'closed';\n        }\n        if (hasChildren \u0026\u0026 node.state.open) {\n            toggleState = 'opened';\n        }\n        \n        return (\n            \u003cTreeNode\n                selected={node.state.selected}\n                depth={node.state.depth}\n                onClick={event =\u003e {\n                    tree.selectNode(node);\n                }}\n            \u003e\n                \u003cToggler\n                    state={toggleState}\n                    onClick={() =\u003e {\n                        if (toggleState === 'closed') {\n                            tree.openNode(node);\n                        } else if (toggleState === 'opened') {\n                            tree.closeNode(node);\n                        }\n                    }}\n                /\u003e\n                \u003cspan\u003e{node.name}\u003c/span\u003e\n            \u003c/TreeNode\u003e\n        );\n    }}\n    \u003c/InfiniteTree\u003e\n);\n```\n\n### Components\n\n#### TreeNode Component\n\n```jsx\nimport React from 'react';\nimport styled from 'styled-components';\n\nconst defaultRowHeight = 30;\n\nconst TreeNode = styled.div`\n    cursor: default;\n    position: relative;\n    line-height: ${({ rowHeight = defaultRowHeight }) =\u003e rowHeight - 2}px;\n    background: ${props =\u003e props.selected ? '#deecfd' : 'transparent'};\n    border: ${props =\u003e props.selected ? '1px solid #06c' : '1px solid transparent'};\n    padding-left: ${props =\u003e props.depth * 18}px;\n    .dropdown {\n        visibility: hidden;\n    }\n    \u0026:hover {\n        background: #f2fdff;\n        .dropdown {\n            visibility: inherit;\n        }\n    }\n`;\n\nexport default TreeNode;\n```\n\n#### Toggler Component\n\n```jsx\nimport React from 'react';\nimport styled from 'styled-components';\n\nconst Toggler = styled(({ state, ...props }) =\u003e (\n    \u003ca {...props}\u003e\n        {(state === 'closed') \u0026\u0026\n        \u003ci className=\"fa fa-fw fa-chevron-right\" /\u003e\n        }\n        {(state === 'opened') \u0026\u0026\n        \u003ci className=\"fa fa-fw fa-chevron-down\" /\u003e\n        }\n    \u003c/a\u003e\n))`\n    color: #333;\n    display: inline-block;\n    text-align: center;\n    margin-right: 2px;\n`;\n\nexport default Toggler;\n```\n\n## Example\n\nhttps://github.com/cheton/react-infinite-tree/blob/master/examples/Tree.jsx\n\n#### TreeNode\nhttps://github.com/cheton/react-infinite-tree/blob/master/examples/components/TreeNode.jsx\n\n#### Toggler\nhttps://github.com/cheton/react-infinite-tree/blob/master/examples/components/Toggler.jsx\n\n# API\n\n### Properties\n\nName | Type | Default | Description\n:--- | :--- | :------ | :----------\nautoOpen | Boolean | false | Whether to open all nodes when tree is loaded.\nselectable | Boolean | true | Whether or not a node is selectable in the tree.\ntabIndex | Number | 0 | Specifies the tab order to make tree focusable.\ndata | Array or Object | [] | Tree data structure, or a collection of tree data structures.\nwidth | Number or String | '100%' | The tree width. It can be a number or string like \"auto\" or \"100%\".\nheight | Number | | The tree height. Setting 100% height is currently not supported. See https://github.com/cheton/react-infinite-tree/issues/8.\nrowHeight \\* | Number, Array, or Function({ node: Node, tree: Tree, index: Number }): Number | | Either a fixed height, an array containing the heights of all the rows, or a function that returns the height of the given node.\nrowRenderer | Function({ node: Node, tree: Tree, index: Number }): React Node | | A row renderer for rendering a tree node.\nloadNodes | Function(parentNode: Node, done: Function) | | Loads nodes on demand.\nshouldSelectNode | Function(node: Node): Boolean | | Provides a function to determine if a node can be selected or deselected. The function must return `true` or `false`. This function will not take effect if `selectable` is not `true`.\nscrollOffset | Number | | Controls the scroll offset.\nscrollToIndex | Number | | Node index to scroll to.\nonScroll | Function(scrollTop: Number, event: React.UIEvent) | | Callback invoked whenever the scroll offset changes.\nonContentWillUpdate | Function() | | Callback invoked before updating the tree.\nonContentDidUpdate | Function() | | Callback invoked when the tree is updated.\nonOpenNode | Function(node: Node) | | Callback invoked when a node is opened.\nonCloseNode | Function(node: Node) | | Callback invoked when a node is closed.\nonSelectNode | Function(node: Node) | | Callback invoked when a node is selected or deselected.\nonWillOpenNode | Function(node: Node) | | Callback invoked before opening a node.\nonWillCloseNode | Function(node: Node) | | Callback invoked before closing a node.\nonWillSelectNode | Function(node: Node) | | Callback invoked before selecting or deselecting a node.\n\n### Tree Methods\n\nhttps://github.com/cheton/infinite-tree/wiki/Functions:-Tree\n\n### Node Methods\n\nhttps://github.com/cheton/infinite-tree/wiki/Functions:-Node\n\n### Node State\n\nName | Type | Description\n:--- | :--- | :----------\ndepth | Number | The depth of a node.\nopen | Boolean | Whether the node is expanded.\npath | String | A unique path string representing a node.\nprefixMask | String | The prefix mask.\ntotal | Number | The total number of child nodes.\n\n#### Flat Tree Structure\n\nhttps://github.com/cheton/flattree/blob/master/examples/tree1.js\n\n```\n\u003croot\u003e: path=\".0\", parent=\"\", children=2, total=11, depth=0, prefix=\"0\", open=1, lastChild=1\nAlpha: path=\".0.0\", parent=\".0\", children=0, total=0, depth=1, prefix=\"00\", open=0, lastChild=0\nBravo: path=\".0.1\", parent=\".0\", children=3, total=9, depth=1, prefix=\"00\", open=1, lastChild=1\nCharlie: path=\".0.1.0\", parent=\".0.1\", children=2, total=4, depth=2, prefix=\"000\", open=1, lastChild=0\nDelta: path=\".0.1.0.0\", parent=\".0.1.0\", children=2, total=2, depth=3, prefix=\"0001\", open=1, lastChild=0\nEcho: path=\".0.1.0.0.0\", parent=\".0.1.0.0\", children=0, total=0, depth=4, prefix=\"00011\", open=0, lastChild=0\nFoxtrot: path=\".0.1.0.0.1\", parent=\".0.1.0.0\", children=0, total=0, depth=4, prefix=\"00011\", open=0, lastChild=1\nGolf: path=\".0.1.0.1\", parent=\".0.1.0\", children=0, total=0, depth=3, prefix=\"0001\", open=0, lastChild=1\nHotel: path=\".0.1.1\", parent=\".0.1\", children=1, total=2, depth=2, prefix=\"000\", open=1, lastChild=0\nIndia: path=\".0.1.1.0\", parent=\".0.1.1\", children=1, total=1, depth=3, prefix=\"0001\", open=1, lastChild=1\nJuliet: path=\".0.1.1.0.0\", parent=\".0.1.1.0\", children=0, total=0, depth=4, prefix=\"00010\", open=0, lastChild=1\nKilo: path=\".0.1.2\", parent=\".0.1\", children=0, total=0, depth=2, prefix=\"000\", open=0, lastChild=1\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheton%2Freact-infinite-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheton%2Freact-infinite-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheton%2Freact-infinite-tree/lists"}