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])