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

179
Views
React push objects within an array to useState array

I have a problem filling an array. Currently variable terapije contains an object within an array based on the if conditions (i've posted a few, but there's way more). I am using useState hook and i set the default value to an empty array which needs to be filled with terapije objects. Currently terapije is filled but my "terapijaForDropdown" is just an empty array. How can i push an existing array to another ? i've tried multiple solutions and nothing seems to work.


 function onSkupinaZdravilChange () {

        if (form.preparati){

            let skupine = form.preparati.map(p => p.preparati && +catalogue.preparat.display[p.preparati].skupinaZdravil.code)
            let terapije = []
            
            if (skupine.length === 1 && skupine.every(i => [1,2,3,4,5].includes(i))){
                terapije.push(findAttributeByCode(catalogue.terapija, '1'))
            }

            if (skupine.length === 2 && skupine.every(i => [1,2,3,4,5].includes(i))){
                terapije.push(findAttributeByCode(catalogue.terapija, '2'))
            }

            if (skupine.includes(6) || (skupine.length === 2 && skupine.includes(6) && skupine.every(i => [1,2,3,4,5].includes(i)))){
                terapije.push(findAttributeByCode(catalogue.terapija, '3'))
            }
                
            if (skupine.length === 1 && skupine.includes(6)){
                terapije.push(findAttributeByCode(catalogue.terapija, '4'))
            }

   setTerapijaForDropdown([...terapijaForDropdown, terapije]);

}}

const [terapijaForDropdown, setTerapijaForDropdown] = useState([]);
useEffect(() => {
        onSkupinaZdravilChange();
     },[form.preparati])

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!