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

263
Visualizações
React JS: How to get the data from 2 components in an array

I want to get the data from an input to a label to display the value onChange, but that don't work when the 2 component are in array:

let expForm = [
    <ExperienceForm
      statePosition={(e) => setPosition(e.target.value)}
      stateCompany={(e) => setCompany(e.target.value)}
      stateCity={(e) => setCity(e.target.value)}
      stateFrom={(e) => setFrom(e.target.value)}
      stateTo={(e) => setTo(e.target.value)}
    />,
  ];

  let expDisplay = [
    <DisplayExperience
      statePosition={position}
      stateCompany={company}
      stateCity={city}
      stateFrom={from}
      stateTo={to}
    />,
  ];

I get and change the value like this:

  const [position, setPosition] = useState("Position");
  const [company, setCompany] = useState("Company");
  const [city, setCity] = useState("City");
  const [from, setFrom] = useState("From");
  const [to, setTo] = useState("To");

But I want to dynamically add and delete with this function that I call with a button:

  const [experienceForm, setExperienceForm] = useState(expForm);
  const [experienceDisplay, setExperienceDisplay] = useState(expDisplay);

  const addComponent = () => {
    setExperienceForm([...experienceForm, expForm]);
    setExperienceDisplay([...experienceDisplay, expDisplay]);
  };

and I display them this way:

{experienceForm}
{experienceDisplay}

I'm new to React Js so feel free to pick me up on things that are obvious to you, thanks in advance.

about 4 years ago · Juan Pablo Isaza
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