Only get input Integers

Only get input Integers
0

so I have this code

 handleChange(event) {
    if (event.target.value === '' || parseInt(event.target.value)) {
      this.props.dispatch({
        type: "SET_INT_INPUT_METHOD",
        payload: event.target.value === '' ? '' : parseInt(event.target.value)
      })
    }
  }

I would like to get input only Integers so how would I implement it in here ?

Quickest fix would be:

if (event.target.value === '' || parseInt(event.target.value) === event.target.value)

Could you explain a little bit why and how it works I am afraid I don’t quite get it :slight_smile:

It doesn’t work, I tested it and it doesn’t record any input I just get the error that there is nothing there.

Fixed it like this

handleChange(event) {
    if (event.target.value === '' || parseInt(event.target.value)) {
      this.props.dispatch({
        type: "SET_INT_INPUT_METHOD",
        payload: isNaN(parseInt(event.target.value)) ? '' : parseInt(event.target.value)

      })
    }
  }

Consider following:

parseInt(0); // 0
parseInt(45andanythingthatfollows); // 45

I suppose both options are unacceptable for you
Now, your question wasn’t about fixing your dispatch function, was it? :slight_smile:
You can just dispatch event.target.value, because you’re already checking value above…