Is is possible to access useEffect in a field condition?
I'm trying to build an attribute manager and my current use case is an array field that takes 2 fields:
1. Relationship to predefined attribute (ex. size, color, etc...)
2. An input of type: text, number, select, informed by the type returend from the attribute relationship
Right now the problem is sibling data only returns the document id for my relationship, but I need to access the relationship values:
{
name: 'attributes',
type: 'array',
fields: [
{
name: 'type',
type: 'relationship',
relationTo: 'attributes',
required: true
},
{
name: 'value',
type: 'text',
required: true,
admin: {
condition (data, siblingData) {
// this loops out of control without useEffect, but I can't seem to get useEffect into scope here...
useEffect(() => {
(async () => {
const type = await fetch(
`${process.env.PAYLOAD_PUBLIC_SITE_URL}${process.env.PAYLOAD_PUBLIC_API_ROUTE}/attributes/${siblingData.type}`
);
console.log(type);
})();
}, [siblingData.type]);
return true
}
}
}
]
},Ended up just using a custom field for my use case.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.