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

259
Views
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
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!