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

166
Vistas
React Hooks Form useFieldsForm Errors doesnt work in first render

I using useFieldArray from react-hooks-form. But when i append new field with a required rules; required error doesnt show on my screen when i submit it. But after that , if i append new field then delete it then i can see that error on my screen. So its not working in first render. So what do i making wrong ? How can i solve it ? My codes :

  const { fields, append,  remove } = useFieldArray(
    {
      control,
      name: "Taxes",
    }
  );

Selecting something from select and finding my model from my list then appending it as a input :

const value=e.target.value;
const model = otherTaxesList.find((x) => x.Id === value);
append(model);

FormInput is simply a Controller with a material UI OutlinedInput

{
  fields.map((item, index, arr) => {
    return (
      <React.Fragment key={item.id}>
        <div className="flex ">
          <FormInput
            className="flex-1"
            control={control}
            name={`Taxes[${index}].model`}
            label={item.Name}
            type="number"
            rules={{ required: customRules.required }}
            error={errors.Taxes?.[index]?.model && errors.Taxes?.[index]?.model}
            placeholder={item.Name}
          />

          <button type="button" onClick={() => remove(index)}>
            Delete
          </button>
        </div>
      </React.Fragment>
    );
  });
}
about 4 years ago · Juan Pablo Isaza
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