Form validation not working with React strap and React hook form version 7. In the above sandbox project, when I click the submit button without entering the text to the bio input getting an error bio field is required. then when I type on that field, the error message, not disappear. Version 7 working very well with normal HTML forms and elements. but getting some conflict with reactstrap.
React version : 17.2 React hook form version : 7.22 Reactstrap version : 9.0
import "./styles.css";
import { Form, FormGroup, Input, Label, Button } from "reactstrap";
import * as Yup from "yup";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
export default function App() {
const schema = Yup.object().shape({
bio: Yup.string().required()
});
const {
register,
handleSubmit,
reset,
formState: { errors }
} = useForm({
resolver: yupResolver(schema)
});
const submitHandle = (data) => {
console.log(data);
};
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<Form onSubmit={handleSubmit(submitHandle)} onReset={reset}>
<FormGroup>
<Label for="bio">Bio</Label>
<Input id="bio" name="bio" type="text" {...register("bio")} />
{errors.bio && <p className="invalid">{errors.bio.message}</p>}
</FormGroup>
<FormGroup>
<br/>
<Button color="primary">Save</Button>
</FormGroup>
</Form>
</div>
);
}
Code sandbox : https://codesandbox.io/s/ancient-smoke-0ccbn