I have a Input with a useForm register where the onChange is not working.
import React, { useState } from "react";
import { useForm } from "react-hook-form";
import { Form, FormGroup, Input } from "reactstrap";
const App = () => {
const [loginData, setLoginData] = useState({
email: null,
password: null
});
const {
register,
handleSubmit,
formState: { errors }
} = useForm();
const submitForm = (data) => {
console.log(data);
};
return (
<div className="row">
<div className="col-sm-12">
<Form onSubmit={handleSubmit(submitForm)}>
<FormGroup className="has-wrapper">
<Input
type="email"
name="email"
id="email"
className="has-input input-lg"
placeholder="Enter Email Address"
value={loginData.email}
onChange={(e) => console.log(e)}
{...register("email", { required: true })}
aria-invalid={errors.email ? "true" : "false"}
/>
<span className="has-icon">
<i className="ti-email"></i>
</span>
{errors.email && (
<span style={{ color: "red" }} role="alert">
required
</span>
)}
</FormGroup>
</Form>
</div>
</div>
);
};
export default App;
When I change the value of email, the onChange is not being called. https://codesandbox.io/s/gracious-chatterjee-3e8i0