Is there a best way to prevent NaN
? I have number input field that whenever I clear the field, I get NaN
.
_amount: function(e) {
var value = parseInt(e.target.value);
var newValue = (value === NaN ? 0 : value); // Thought this could work
},
<input type="number" value={this.state.amount} onChange={this_amount} />
Now in my render I have 400 - this.state.amount
. The things is, when I clear the input field, amount state is null
. How to prevent this? Is it possible that when I clear the field I get zero? Say I type in 3
then clear the field, NaN
pops up.
Thanks