Today I find use parseInt()
is also a good and clean practice. A onChange(e)
example is below.
onChange(e){
this.setState({[e.target.id]: parseInt(e.target.value) ? parseInt(e.target.value) : ''})
}
parseInt()
would return NaN
if the parameter is not a number.parseInt('12a')
would return 12.