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

229
Views
How can I get top element behavior on children?

Hello thanks for the help in advance. I explain the behavior I want to achieve in react. Here is the sandbox for a better understanding. The behavior of the code is as follows:

There is a div marked with a 1px border and inside it there is a button and another div where it will render an array. Clicking on the button adds that same button to the array and renders it alongside the first one. Multiple clicks on the first button will generate a column of buttons next to the first button. So far so good.

What I want to achieve is that clicking on any of the buttons in the column generates another column of buttons next to the button we click on. And so on. At this point, I'm stuck. Thank you.

import "./styles.css";
import { useState } from "react";

export default function App() {
  const [btnCount, setBtnCount] = useState([]);

  const style = {
    maxWidth: "100px",
    display: "flex",
    padding: "10px",
    border: "solid 1px"
  };

  function handleAdd() {
    setBtnCount(btnCount.concat(btn));
  }

  const btn = <button onClick={handleAdd}>Click</button>;

  return (
    <div>
      <div style={style}>
        <div style={{ margin: "5px" }}>{btn}</div>
        <div>
          {btnCount.map((e, index) => {
            return <div key={index}>{e}</div>;
          })}
        </div>
      </div>
    </div>
  );
}
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!