I'm making a react app, I have 3 inputs(champ1, champ2, champ3) where I type values and I get the sum of them in another one, and that sum is used in a formula that's calculated in another input.
I get this error: "Warning: Received NaN for the value attribute. If this is expected, cast the value to a string." when I type and clear the inputs, it reads an empty value, what can I do to prevent that?
Here's my code:
const [input, setInput] = React.useState({
champ2: 0,
champ4: 0,
champ6: 0,
});
const [sum, setSum] = React.useState(0)
const [eau, setEau]=React.useState(0)
useMemo(() => {
setSum(parseInt(input.champ2) + parseInt(input.champ4) + parseInt(input.champ6))
}, [input])
useMemo(() =>{
setEau(sum*0.02*4*8000)
},[sum])
//handle input change
const handleInput=function(e){
setInput({
...input,
[e.target.name]: e.target.value
});
}