I have a readOnly input that calculates a value based on two other inputs (qty and price). In the getLineTotal() function, I am trying to validate the inputs and am having an issue when the input receives a blank value.
const getLineTotal = (e: any): void => {
let parsedPrice: number;
console.log(typeof e.target.value)
if(Number.isNaN(e.target.value)){
console.log("yes")
parsedPrice = 0;
}
else{
parsedPrice = parseInt(e.target.value);
}
setPrice(parsedPrice);
console.log(qty, parsedPrice, "=>", qty * parsedPrice)
setTotal(qty * parsedPrice);
}
I have tried multiple different methods of detecting this NaN value, but nothing has worked. The console says it's a string but then says received NaN for value attribute.
string
LineDetail.tsx:38 12 12 '=>' 144
LineDetail.tsx:29 string
LineDetail.tsx:38 12 NaN '=>' NaN
Any ideas?