Hi, as in the title is it possible to pass it? Now i'm passing only path to the component, but i would like to pass a certain field name to be used as a label
Ok, thats how I've figured it out (almost). I'm taking a name of the first field in array, then reading its value from 'data'. If first field's value is empty I'm returning default field labels.
How to correctly set type of Props?
'use client'
import { useRowLabel } from '@payloadcms/ui'
import React from 'react'
import { ArrayFieldServerProps, LabelsClient } from 'payload'
type Props = Pick<ArrayFieldServerProps, 'field'> & {
field: {
fields: Array<{ name: string }>
}
labels: LabelsClient
}
export const ArrayRowLabel: React.FC<Props> = ({ field }) => {
const { data, rowNumber } = useRowLabel<{ groupTitle?: string }>()
const firstFieldName = field?.fields[0]?.name
const fieldNameToLabel = firstFieldName && typeof firstFieldName === 'string' && firstFieldName
const defaultFieldLabel = field.labels?.singular
const customLabel =
(fieldNameToLabel && data[fieldNameToLabel]) ||
`${defaultFieldLabel} ${String(rowNumber! + 1).padStart(2, '0')}`
return <div>{customLabel}</div>
}
Custom components can be defined in the following format as well:
{
path: '/path/to/comp#NamedIfNecessary`,
clientProps: { ... } // This can be custom props you want to pass to the component which payload will include
}
Thank you! Finally somebody answered here... I'll give it a try tomorrow
It works. Thank you for help ❤️
My pleasure
Star
Discord
online
Get dedicated engineering support directly from the Payload team.