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

198
Vistas
How to get the relevant error message when using React-hook-forms in a loop ,

I have a loop that creates input fields. I managed to make it validate using react-hook-form and yup. but I cannot get the error message because of a variable issue...

{Object.getOwnPropertyNames(row)?.map((head) => {
                    return (
                      <div key={head} className="row my-2">
                        <div className="col-5">{createHeads(head)}</div>
                        <div className="col-7">{createInputs(head)}</div>
                        <div className="col-12">
                          <small className="text-danger">{errors.head?.message}</small>
                        </div>
                      </div>
                    );
                  })}

So head is a variable that contains the name of the input field. but it's not using that variable . is there a way around it?

--Edit

function createInput(head){
  return <input type="text" name="head" {...register(head)} />
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

{Object?.getOwnPropertyNames(row)?.map((head) => {
                    const error = Object.getOwnPropertyNames(errors).filter((error) => error == head);

                    return (
                      <div key={head} className="row my-2">
                        <div className="col-5">{createHeads(head)}</div>
                        <div className="col-7">{createInputs(head)}</div>
                        <div className="col-12">
                          <small className="text-danger">{errors[error]?.message}</small>
                        </div>
                      </div>
                    );
                  })}

Update im just dumb edit :

{Object?.getOwnPropertyNames(row)?.map((head) => {
                    return (
                      <div key={head} className="row my-2">
                        <div className="col-5">{createHeads(head)}</div>
                        <div className="col-7">{createInputs(head)}</div>
                        <div className="col-12">
                          <small className="text-danger">{errors[head]?.message}</small>
                        </div>
                      </div>
                    );
                  })}
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