Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

useField return values are without content - only id

default discord avatar
_yiorgoslast year
2

Trying to make a custom component, and getting this behaviour.


Does payload defaultValue not work well with custom components?



I am on beta.80


Is this the expected behavior, or am I missing something?



  fields: [
    {
      name: 'color-picker',
      type: 'array',
      label: 'Color Picker',
      defaultValue: () => [
        { variableName: 'name1', color: 'color1' },
        { variableName: 'name2', color: 'color2' },
      ],
      fields: [
        {
          name: 'variableName',
          type: 'text',
        },
        {
          name: 'color',
          type: 'text',
        },
      ],
      admin: {
        components: {
          Field: 'src/ui/color-picker',
        },
      },
    },
  ],


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

  console.log({ value, rows })
  //{
  //     "value": 2,
  //     "rows": [
  //         {
  //             "id": "66c04810bc9f85984eccbf0c"
  //         },
  //         {
  //             "id": "66c04810bc9f85984eccbf0d"
  //         }
  //     ],
  // }
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.