#Handling Arrays with useField in NextJS

1 messages · Page 1 of 1 (latest)

woeful shadowBOT
#

did anyone use useField for client side custom component . if yes then i need useField to be an array i am new to nextjs and payload please help . i am switching from vuejs so i am too young to handle states in react 😦

// Initialize faqs state based on the value from useField
  const [faqs, setFaqs] = useState<Array<{ question: string, answer: string, id: string }>>(
    Array.isArray(value) ? value : []
  );```

here how my custom Faqs will look like

```{
      name:'customFaqs',
      type: 'array',
      label: 'Custom FAQs',
      defaultValue: [{ question: '', answer: '' }],
      fields: [
        {
          name: 'question',
          type: 'text',
          label: 'Question',
        },
        {
          name: 'answer',
          type: 'textarea',
          label: 'Answer',
        },
      ],
      admin: {
        // Specify your custom component here
        components: {
          Field: FAQTabs,
        },
      },
    },```
i think useField need to return an array but its returning 0 in value 😦
is this right thing i am doing
echo abyssBOT
#

Original message from @untold panther - Moved from #off-topic message

somber rivet
#

Try this
const [fields, dispatchFields] = useAllFormFields() const formData = reduceFieldsToValues(fields, true)

rose mist
#

The data in the format of array is splitted into the objects.
which is not correct, how to get the array field properly?