Home > OS >  React JS How to add individual functions to the numeric input arrows?
React JS How to add individual functions to the numeric input arrows?

Time:09-21

as we know input of type number have 2 arrows integrated (ss attached)

enter image description here

I will like to know if you can add different functions, one to each of the arrow. I have for example the following code but it only adds 1 regardless of the arrow you press:

<input onChange = {(e) => {mas(productos.descripcion, productos.cantidad,e.target.valueAsNumber)}}
 type = 'number'
 pattern = "[0-9]*"
 required
 value = {productos.cantidad}
/>

I would like to add another function so that way I can use both arrows one for 1 and the other one for --1. Any tips, help, documentation is appreciate it.

CodePudding user response:

onChange just get the current input value, if you want to know if it's 1 or --1, you can compare current value e.target.valueAsNumber with previous value productos.cantidad.

  • Related