-
We're building a custom UI field. It looks like this: import { merge } from 'lodash';
import { Field } from 'payload/types';
import { LinkTo } from './ui/LinkTo';
interface Options {
collectionSlug: string;
}
// By dynamically building fields in code configurations are reusable and concise
export const linkTo = (options: Options, overrides?: Partial<Field>): Field => {
const { collectionSlug } = options;
return merge<Field, Partial<Field> | undefined>(
{
name: 'linkTo',
type: 'ui',
admin: {
position: 'sidebar',
components: {
Field: (props: Field) => (
<LinkTo {...props} collectionSlug={collectionSlug} />
),
},
},
},
overrides
);
};
// usage
const Tag = {
slug: 'tags',
fields: [
//...
linkTo({ collectionSlug: 'tags' }),
//...
]
} You can see two twisted place:
I think if I can get the current collection slug directly in the
I think if I can pass some custom configurations would be much easier:
|
Beta Was this translation helpful? Give feedback.
Answered by
Stupidism
Aug 21, 2022
Replies: 1 comment
-
I found I can get the current collection info with hook:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Stupidism
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found I can get the current collection info with hook:
useDocumentInfo
. It can solve this specific issue for now: