Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda