score:3

Accepted answer

you can do:

comp.proptypes = {
  lastpalletbagcount: proptypes.oneoftype([
    proptypes.number,
    proptypes.oneof([''])
  ]).isrequired
}

score:0

i think,

  const [lastpalletbagcount, setlastpalletbagcount] = react.usestate<number>();

  const handler = (e: any) => {
    console.log(e.target.value)
    const numberregex = /^[0-9\b]+$/;

    if (numberregex.test(e.target.value)) {
      var val = number(e.target.value);
      setlastpalletbagcount(val);

    }

  }

  return (
      <input
        type={'text'}
        classname={'bag-count'}
        value={lastpalletbagcount}
        onchange={(e) =>
          handler(e)
        }
      />
  );

would work for you.

but you would have to change the value in event in the onchange to number with some logic , because your input type is string and would return a value of type string.


Related Query

More Query from same tag