What do you mean by update it with?
Right now I trying to show the array by using {this.state.arr} in the last return.
,Some minutes later
I finally got what you meant now.
I am getting the target id and the target quantity as expected, I tried only pushing the id and the quantity in the array before and it worked fine but what it did was only pushing every time I clicked the button so I got it to display for example 11 (id:1,quantity:1) when I clicked the first button then 1121 when I clicked the second one and 112131 the third one, if I changed the quantity of the first for example I would get 11213114.(if the quantity was 4)
I don’t know about all the 11 or the 112131 stuff, because I can not see the code which renders something based on the state change of the click event, but I will take your word for it. You never explained how you wanted to update arr based on the id and quantity arguments passed to handleOnClick method, so it was difficult to guess what the problem was.
If the problem was in the handleOnClick method, you still were not explaining how you were expecting this.state.arr to look after a given call to the method. In your original post, all you did was post some code and then said “i don’t know why it doesn’t work.” How are we supposed to know what you mean by “it doesn’t work”, without knowing how you expect it to work?
Anyway, I am glad you figured it out, but in the future, you will get a better response if you explain what you want a piece of code to do and explain what it is doing instead.
I didn’t figure it out actually, it doesn’t work yet.
To be honest the post was posted by mistake without me wanting to but I left it as it was because the wiFi didn’t work. Then I didn’t give it much importance later and I tried to find a way by myself. I will try to make a jsfiddle of what I want to see if I find a solution that works.
I don’t mind helping you figure out a solution and if you have a Codepen or JSFiddle that you want us to look at, we can do that for sure. Just make sure you explain what you expect to happen when a user does something (i.e. click on a button) and what is happening instead. That way, we can know where to look in the code to give you suggestions.