I am working on a ReactJS application, where I have a JSON which is coming from database and stored inside Redux store.
{
prodName: "Name",
quantity: 5
}
Using quantity property of this object, I am rendering an input on screen like shown below.
<input type="number" value=quantity onChange={this.handleQuantityChange} />
with the handleQuantityChange here:
handleQuantityChange(event) => {
if(event.target.value > 0) updateQuantity(event.target.value);
}
updateQuantity() function triggers an action and updates quantity in database and hence update the JSON which renders the updated quantity on screen.
Till here everything is fine.
The issue is, I am not able to update quantity after a single digit is entered. Like in this example, I can make this quantity from 5 to 51, 52, 53 or 510 or 5200 and so on but I am not able to make it 6 or 7 or 2.
This is happening because of an if condition given in handleQuantityChange function, but I can't remove the condition as API throws an error on sending NaN or 0 value.
Also tried storing this quantity in a localState of component but then the database value and input value do not sync with each other and for updating quantity, we have only one onChange event occurring.
Any method on how to manage this onChange function.
Thanks in advance.
valueAsNumber.valueis a string for all input controls, but numerical ones have the other one as well.parseInt()(orparseFloat()) onvalue.