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

228
Vistas
React-hook form useFieldArray: In my codes, is this possible to lessen the array or not?

I have this data when I console.log(data):

export const data = [
  {
    test: [
      {
        product: "Shirt1",
        variantion: [
          { size: "M", color: "blue" },
          { size: "S", color: "blue" }
        ]
      },
      {
        product: "Shirt3",
        variantion: [
          { size: "L", color: "red" },
          { size: "M", color: "blue" }
        ]
      }
    ]
  }
];

Instead of having the test, can it be converted to something like this? Or will it cause any problems in the future since this is a nested array?

export const data = [
  {
    product: "Shirt1",
    variantion: [
      { size: "M", color: "blue" },
      { size: "S", color: "blue" }
    ]
  },
  {
    product: "Shirt3",
    variantion: [
      { size: "L", color: "red" },
      { size: "M", color: "blue" }
    ]
  }
];

codesandbox link: https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-2-efwq6

I tried removing the test

const defaultValues = {
  test: [
    {
      product: "",
      nestedArray: [{ size: "", color: "", design: "" }]
    }
  ]
};

But it will have these errors:

/src/index.js: Unexpected token (11:4) 9 | const defaultValues = { 10 | > 11 | { | ^ 12 | product: "", 13 | nestedArray: [{ size: "", color: "", design: "" }] 14 | }
browser
Parsing error: Unexpected token 9 | const defaultValues = { 10 | > 11 | { | ^ 12 | product: "", 13 | nestedArray: [{ size: "", color: "", design: "" }] 14 | } (null)
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