Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
How to access the error message using yup and react-hook-form through formState?

I'm trying to display the error message I set using yup validation - my schema for displayName looks like this:

 displayName: yup.string().required("Please enter a username")

I'm using react-hook-form for my forms and my textfield goes something like this:

    <Controller
      render={({ field, formState }) => (
      <TextField
      {...field}
      label="display name"
      error={!!formState.errors?.displayName}
      helperText={!!formState.errors?.displayName ? formState.errors?.displayName.message : null}
      />
     )}
     name="displayName"
     control={control}
     defaultValue=""
    />

Unfortunately, my screen goes blank. I tried looking for the reason why it happened and apparently, it's because of formState.errors?.displayName.message but at the same time, it contains the error message for my field. Is there any way I can access it so I can use it for my helperText?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Is your TextField a component of MUI?
I tried to reproduce it with MUI + RHF + yup in the same way,

Is there any way I can access it so I can use it for my helperText?

It seems that the error is output to helperText without any problem.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda