payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
25.48k stars 1.62k forks source link

useField on array fields return array length as value and row[] showing only IDs #8146

Open yonnic opened 2 months ago

yonnic commented 2 months ago

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.15.1
  npm: 10.7.0
  Yarn: 1.22.22
  pnpm: 9.9.0
Relevant Packages:
  payload: 3.0.0-beta.101
  next: 15.0.0-canary.104
  @payloadcms/db-mongodb: 3.0.0-beta.101
  @payloadcms/email-nodemailer: 3.0.0-beta.101
  @payloadcms/email-resend: 3.0.0-beta.101
  @payloadcms/graphql: 3.0.0-beta.101
  @payloadcms/next/utilities: 3.0.0-beta.101
  @payloadcms/plugin-cloud: 3.0.0-beta.101
  @payloadcms/plugin-cloud-storage: 3.0.0-beta.101
  @payloadcms/richtext-lexical: 3.0.0-beta.101
  @payloadcms/storage-s3: 3.0.0-beta.101
  @payloadcms/translations: 3.0.0-beta.101
  @payloadcms/ui/shared: 3.0.0-beta.101
  react: 19.0.0-rc-06d0b89e-20240801
  react-dom: 19.0.0-rc-06d0b89e-20240801
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10

Describe the Bug

Lets say i have such a field of type array and a text field inside

{
      name: 'headlines',
      label: 'Headlines',
      type: 'array',
      fields: [
        {
          name: 'headline',
          type: 'text',
          required: false,
        },
      ],
    },

In a custom component i want to set new headlines.

const {value, rows, setValue } = useField({ path: 'headlines', hasRows: true })

Now the problem is that value is just the length of the array and rows is an array of Ids but missing the actual headline data. I guess thats not suppose to happen. There is no info about this in the docs.

Reproduction Steps

create such a field

{
      name: 'headlines',
      label: 'Headlines',
      type: 'array',
      fields: [
        {
          name: 'headline',
          type: 'text',
          required: false,
        },
      ],
    },

and try to get the data in a custom field component

Adapters and Plugins

No response

georgecartridge commented 1 month ago

+1

I'm using Payload 2.0.0 and have come across this today. When logging the value returned from useField, it simply returns the length of the array