Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda