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

111
Views
Update an object of array using usestate

I have an object like this :

{
  name:"lorem ipsum",
  skills:[]
}

Now, I have a form where users add their skills and I want to update the object using usestate hook according to the input of that form

For example, if user adds HTML,CSS and JavaScript in the form, the object should look like this :

{
  name:"lorem ipsum",
  skills:['html','css','JavaScript']
}

How can I achieve this?

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

0

You could separate the name and skills into two different variables, but if you insist on keeping it as one object here is what you could do:

const [obj, setObj] = useState({name:"lorem ipsum",skills:[]}

To initialise your state, and let's say the list of skills you receive from the form is called form_skills:

setObj({...obj, skills: form_skills})

This makes use of the spread operator which basically copies your object into a new one and replaces all values with the keys you define afterwards, in this case only skills (or adds to the object).

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!