score:0

the question you have asked is a bit unclear. but as far as i understand there could be 2 issues :

  1. change const quantities = [...this.state.quantities]; to let quantities = [...this.state.quantities]; since you'll be pushing new values to the array.
  2. let qua = e.target.textcontent; not sure if this is the best way to get the value. try let qua = e.target.value; and pass the value param in anchor tag <a onclick={this.targetvalue} value={i+1} key={i} href="#">{i + 1}</a>

sharing the output for what you tried will definitely help to understand better.

score:0

the best way to push elements to a state array in react. you can do this

   const newquantity = {name: this.props.name, quantity: qua};
   this.setstate(previousstate => ({
       quantities : [...previousstate.quantities, newquantity]
   }));

also don’t use multiple setstates inside handler function use one that’s enough :)


Related Query

More Query from same tag