score:0

remove matches from your default state declaration, then, in your condition try something like this :

if(true /** your condition */) {
  setformdata({
   ...formdata, /** current data*/
   matches:[] /** add your key matches with correct array value.*/
  })
}

i guess probably something like this ? :

if(matchsarray && array.isarray(matchsarray) && matchsarray.length > 0) {
  setformdata({
   ...formdata, /** current data*/
   matches:matchsarray /** add your key matches with correct array value.*/
  })
}

don't forget to put your data state in a real formdata to build your post request after. like :


const finalformdata = new formdata()

finalformdata.append(
  'data', /** your key catch by your backend api*/ 
  formdata /** the react state*/
)

let me know if it's help you. :)

score:1

you can write the sending part inside a useeffect.

useeffect(
        () => {
            yourvariable && sendingfucntion();
        }, 
        [yourvariable]
    )

Related Query

More Query from same tag