problem with input type number
Hi guys, when the value of quantity is 0 and I enter 1 the input field display "01" while the quantity is 1. Can anyone help me explain why ? I'm using MUI. This case only occurs when I use type number. With type text, it worked
7 Replies
Here is codesandbox: https://codesandbox.io/p/sandbox/priceless-heisenberg-3wl24f?file=%2Fsrc%2FApp.js
Looks like you've fixed this now..? You appear to have changed the
value={quantity}
to value={quantity.toString()}
now..? Did that fix the issue for you?Yeah. But idk why
Did you originally have += instead of +? That would have concatenated the new value to the previous one. Changing that to a plus performs the unary plus operation of converting a string to a number.
No, I use plus operation to convert string to a number
fyi, you can also use
.valueAsNumber()
Not a function. So just
.valueAsNumber