Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Tree hierarchy with proper indentation

I'm trying to resent a tree with proper indentation using index and adding it as a style.

It partially does its job as it shows indentation of parent and its sub children yet doesn't represent the indentation between a child and a grandchild.

the data :

items: [
    {
      label: 'A',
      checked: true,
      items: [
        {
          label: 'sub A-1',
          checked: true,
          items: [
            {
              label: 'sub A-1-2',
              checked: true,
              items: [
                {
                  label: 'sub A-1-2-1',
                  checked: true,
                },
              ],
            },
          ],
        },
        {
          label: 'Sub A-2',
          checked: true,
        },
      ],
    },
    {
      label: 'B',
      checked: false,
      items: [
        {label: 'B-1', checked: false},
        {label: 'B-2', checked: false},
      ],
    },
  ],

the code:

export const ReportTree = (data: ReportTreeProps) => {
  return (
    <div>
      <ul>
        {data.items.map(node => (
          <TreeNode node={node} key={node.value} />
        ))}
      </ul>
    </div>
  )
}

function TreeNode({node, index}) {
  return (
    <li>
      <div className=" flex flex-row items-center gap-2  p-2">
        <div className={`pl-${5 + index}`}>{node.label}</div>
        <input type="checkbox" name={node.label} />
      </div>
      {node.items && (
        <div>
          <ul>
            {node.items.map((child, index) => (
              <TreeNode key={child.value} node={child} index={index} />
            ))}
          </ul>
        </div>
      )}
    </li>
  )
}

How it looks : enter image description here

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!