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

382
Vistas
React-Hook Form: How to make a reusable component for Autocomplete which will be used inside the useFieldArray?

I have this Autocomplete component

const Select = ({ name, control, defaultValue }) => {
  return (
    <div>
      Select
      <Controller
        as={
          <Autocomplete
            id="product"
            multiple
            style={{ width: 300 }}
            options={name}
            autoHighlight
            renderInput={(params) => (
              <TextField
                {...params}
                label="Product"
                variant="outlined"
                fullWidth
              />
            )}
          />
        }
        name="country"
        control={control}
      />
    </div>
  );
};

export default Select;

This is the FieldArray where I will be using this component:

const FieldArray = ({ control, register, setValue, getValues }) => {
  const { fields, append, remove, prepends } = useFieldArray({
    control,
    name: "order"
  });

  renderCount++;

  return (
    <div>
      <ul>
        {fields.map((item, index) => {
          return (
            <li key={item.id}>
              <Select control={control} />
              <select {...register(`order.${index}.product`)}>
                <option value="shirt1">shirt1</option>
                <option value="shirt2">shirt2</option>
                <option value="shirt3">shirt3</option>
              </select>

              <button type="button" onClick={() => remove(index)}>
                Delete
              </button>
              <NestedArray nestIndex={index} {...{ control, register }} />
            </li>
          );
        })}
      </ul>
      <section>
        <button
          type="button"
          onClick={() => {
            append({ name: "append" });
          }}
        >
          Add product
        </button>
      </section>
    
    </div>
  );
};

export default FieldArray;

For now, I have commented the Select in my codesandbox because this will always cause an error that says e.render is not a function

How can I make a reusable AutoComplete component?

Codesandbox: https://codesandbox.io/s/react-hook-form-wizard-form-complete-nnew-hvu5t8?file=/src/fieldArray.js:498-531

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