I have an
arrayfield that lets the user select an item from a collection with a
relationshipfield. I'd like to use the
titlefield of that item for the
RowLabel, but the
relationshipfield returns the item
id. I've seen that there's a Local API that can be used to asynchronously retrieve data (e.g. with
findById), but
RowLabeldoesn't accept
Promiseas a return value.
Is there an easy way to do this?
Sorry just found this question, seems to answer my question
https://discord.com/channels/967097582721572934/1097588914732150865/1097608591793455164For anyone else who comes across this, a solution that uses
fetchinstead of
axiosadmin: {
components: {
RowLabel: ({ data, index = 0 }) => {
const [label, setLabel] = useState(`Feature ${String(index).padStart(2, '0')}`)
useEffect(() => {
fetch(
`${process.env.PAYLOAD_PUBLIC_SITE_URL}${process.env.PAYLOAD_PUBLIC_API_ROUTE}/features/${data.feature}`
).then(async (res) => {
setLabel((await res.json()).title)
})
}, [data.feature])
return label
},
},
},just saved me, thanks. This would be a great add to the
rowLabeldocs. Or even better adding a
depthfield parameter somewhere in
adminto do this automatically
This also helped me. thanks
@492539613034971146!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.