You are getting the "Invalid email" error because your fieldValues.email is set to false (a boolean) instead of the actual email string. The regex validation fails because it’s not checking a string.
so, change this const [fieldValues, setFieldValues] = useState({ name: false, email: false, message: false, }) to const [fieldValues, setFieldValues] = useState({ name: "", email: "", message: "", })
here, stateKey is also passing boolean value insted of string so change this code, const handleInputClick = (stateKey) => { setFieldValues({ ...fieldValues, [stateKey]: true, }) } to this, const handleInputChange = (e, stateKey) => { setFieldValues({ ...fieldValues, [stateKey]: e.target.value, }) }
Probably, this work for you.