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

250
Views
how to make children when I click on parent and the children should open another children no matter how times its clicked

(In React.js) I want to make a parent, when I click on parent it should open a child and when I click that child it should open another child with the the first one and goes on even when I click the parent once again it should open a child (Separate one).

***App.tsx***
import React, { useCallback, useState } from 'react';
import './App.css';

import { FileNode, root } from './data';

const File: React.FC<FileNode> = ({ id, children }: FileNode) => {
  const [showChildren, setShowChildren] = useState<boolean>(false);
  const handleClick = useCallback(() => {
    setShowChildren(!showChildren);
  }, [showChildren, setShowChildren])

  return (
    <div>
      <span onClick={handleClick}>
        <h4 style={{ fontWeight: showChildren ? 'bold' : 'normal' }}>{id}</h4>
        {/* <h3 style={{fontWeight: showSubChildren? 'italic' : 'normal'}}>{subChildren}</h3> */}
      </span>
      <div style={{ position: 'relative', display: 'flex', flexDirection: 'column', left: 25, borderLeft: '1px solid', paddingLeft: 15 }}>
        {showChildren && (children ?? []).map((node: FileNode) => <File {...node}/>)}
      </div>
    </div>
  )
}

function App() {
  return (
    <div style={{ marginLeft: 15 }}>
      <File {...root}/>
    </div>
  );
}

export default App;
*****data.ts*****

import { Children } from "react";

export interface FileNode {
    id: string
    children?: FileNode[]
    // subChildren?: string
  }
  
  export const root: FileNode = { id: "Computer", children: [{ id: "Information", children: [{
            id: "Software", children: [{
            id: "Hardware",children:[{id: "Mouse",children:[{id: "keyboard",
            children:[{id: "USB", children:[{id: "Touch Pen",children:[{id: "CD ROM",
            children:[{id: "Combo CD DVD",children:[{id: "Screen",children:[{id: "LCD",
            children:[{id: "LED", children:[{id: "CPU", children:[{id: "WebCam",
            children:[{id: "RAM", children:[{id: "SSD", children:[{id: "Graphic Card",
            children:[{id: "WiFi Card", children:[{id: "Gaming Card",
            children:[{id: "Linux", children:[{id: "Ubuntu",}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]},
          ]}]
          },
          ]
          }
about 4 years ago · Santiago Trujillo
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!