React UI Component for directory structure.
npm install direactree
# or
yarn add direactreeimport Direactree from 'direactree';
const structure: TreeNode[] = [
{
id: '0',
name: 'Desktop',
type: 'folder',
children: [
{
id: '1',
name: 'Projects',
type: 'folder',
children: [
{
id: '1.1',
name: 'Web Applications',
type: 'folder',
children: [
{
id: '1.1.1',
name: 'React Projects',
type: 'folder',
children: [
{
id: 'sample.txt',
name: 'project-notes.txt',
type: 'file',
},
{
id: 'example.json',
name: 'config.json',
type: 'file',
},
{
id: 'sample.ts',
name: 'utils.ts',
type: 'file',
}
],
},
],
},
],
},
{
id: '2',
name: 'Documents',
type: 'folder',
children: [
{
id: '2.1',
name: 'Technical Documents',
type: 'folder',
children: [
{
id: '2.1.1',
name: 'API Documents',
type: 'folder',
children: [
{
id: '2.1.1.1',
name: 'REST-API.md',
type: 'file',
}
],
},
],
},
],
},
]
}];
function App() {
return (
<div>
<Direactree structure={structure} />
</div>
);
}In Next.js 13 and later versions, all components are considered Server Components by default. Since Direactree is a Client Component, you have two different usage methods:
// This import automatically includes the 'use client' directive
import Direactree from 'direactree/next';
function MyComponent() {
return (
<div>
<Direactree structure={structure} />
</div>
);
}
export default MyComponent;'use client';
import Direactree from 'direactree';
function MyComponent() {
return (
<div>
<Direactree structure={structure} />
</div>
);
}
export default MyComponent;npm install
# or
yarnnpm run storybook
# or
yarn storybooknpm run build
# or
yarn buildMIT

