mirror of
https://github.com/strapi/strapi.git
synced 2025-11-26 07:01:14 +00:00
improves to useCustomFields typescript
This commit is contained in:
parent
24fa0fbf32
commit
a6a9fc1648
@ -20,7 +20,8 @@ const CustomIcon = ({ customFieldUuid }) => {
|
|||||||
const customField = customFieldsRegistry.get(customFieldUuid);
|
const customField = customFieldsRegistry.get(customFieldUuid);
|
||||||
|
|
||||||
if (customField?.icon) {
|
if (customField?.icon) {
|
||||||
return customFieldIcon;
|
const CustomFieldIcon = customField.icon;
|
||||||
|
return <CustomFieldIcon />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Placeholder />;
|
return <Placeholder />;
|
||||||
@ -35,8 +36,7 @@ import { Typography } from '@strapi/design-system';
|
|||||||
|
|
||||||
const CustomFieldsList = () => {
|
const CustomFieldsList = () => {
|
||||||
const customFieldsRegistry = useCustomFields();
|
const customFieldsRegistry = useCustomFields();
|
||||||
const customFields = customFieldsRegistry.getAll();
|
const registeredCustomFields = Object.entries(customFieldsRegistry.getAll());
|
||||||
const registeredCustomFields = Object.entries(customFields.getAll());
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -62,22 +62,18 @@ With this method from `useCustomFields` hook, you will receive a dictionary cont
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
interface CustomField {
|
interface CustomField {
|
||||||
components: Object;
|
components: object;
|
||||||
icon: React.ComponentType;
|
icon: React.ComponentType;
|
||||||
intlDescription: IntlObject;
|
intlDescription: IntlObject;
|
||||||
intlLabel: IntlObject;
|
intlLabel: IntlObject;
|
||||||
name: string;
|
name: string;
|
||||||
options: Object;
|
options: object;
|
||||||
pluginId: string;
|
pluginId: string;
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomFields = {
|
|
||||||
[uid: string]: CustomField;
|
|
||||||
};
|
|
||||||
|
|
||||||
type UseCustomFields = () => {
|
type UseCustomFields = () => {
|
||||||
get: (uid: string) => CustomField | undefined;
|
get: (uid: string) => CustomField | undefined;
|
||||||
getAll: () => CustomFields;
|
getAll: () => Record<string, CustomField>;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user