Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!