I am building a shopping cart project.
One of the features that I am trying to build for my Cart page is an input value displaying the quantity for each product in the cart (so that the user can manually adjust the number of products) as well as a button either side of the input to decrement/increment the quantity by 1.
Here is a link to my codesandbox, and the issue can be recreated by adding one of any item to the cart:
https://codesandbox.io/s/yqwic
The logic I have built for manually adjusting the input field works as intended, however when I click the increment/decrement buttons it is only adjusting the number of items in the cart display in the navbar. The input field is not updating - however when looking at the React-Developer-Tools components debugger, the underlying quantity is updating to the correct figure - it is just not rerendering the input value in the DOM.
Can anyone point out where I might be going wrong? I tried switching defaultValue
to value
in the input field however this prevents me from manually adjusting the input.
Thanks