I'm trying to create form with React Hook Form with Material UI TextField. It seems I configured it properly but the error message doesn't appear and I don't know why. I put just the main parts of the code.
import { TextField } from "@material-ui/core";
import { Controller, useForm } from "react-hook-form";
type NovoSinistroForm = {
codigoCobertura: number;
telefoneResponsavel: string;
evento: number;
dataEvento: Date;
dataEstimadaColheita: Date;
areaAtingida: number;
nomeComunicante: string;
nomeResponsavelVistoria: string;
relacaoComunicanteResponsavel: string;
emailComunicante: string;
telefone1Comunicante: string;
telefone2Comucante: string;
}
const {
control,
formState,
handleSubmit,
watch,
} = useForm<NovoSinistroForm>();
<form onSubmit={onSubmit}>
<Controller
name="nomeResponsavelVistoria"
control={control}
rules={{
required:{
value: true,
message: "Campo obrigatório."
}
}}
render={({
field,
fieldState: { invalid, isTouched, isDirty, error },
}) => (
<TextField
{...field}
innerRef={field.ref}
label="Responsável por vistoria"
type="text"
InputLabelProps={{
shrink: true,
}}
error={invalid && isTouched}
helperText={error?.message}
/>
)}
/>
</form>
