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

96
Views
How to push to an array in useState with multiple field in array element
const[data, setDate] = useState({
  field1 : [{
     f1: "",
     f2: "",
  }],
  field2: [{
     f3: "",
     f4: "",
  }]
})

In the above how I can update and push new element to field1 and field2

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You may try the following:

let temp={...data};
temp.field1.push(...);
temp.field2.push(...);

setDate(temp);
about 4 years ago · Juan Pablo Isaza Report

0

const [data, setDate] = useState({
    field1: [
      {
        f1: "",
        f2: ""
      }
    ],
    field2: [
      {
        f3: "",
        f4: ""
      }
    ]
  });
  useEffect(() => {
    let temp = { ...data };
    temp.field1.push({ f3: "" });
    setDate(temp);
  }, []);
about 4 years ago · Juan Pablo Isaza Report
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!