useResource
useResource
is used to get resources
that are defined as property of the <Refine>
component.
import { useResource } from "@pankod/refine-core";
const { resources } = useResource();
// it also returns the resource with the props you provide as resourceNameOrRouteName.
const { resource } = useResource({
resourceNameOrRouteName,
});
API Reference
Properties
Return value
Description | Type |
---|---|
resources | IResourceItem[] |
resource | IResourceItem |
resourceName | string |
id | BaseKey |
Interfaces
type OptionsProps<TExtends = { [key: string]: any }> = TExtends & {
label?: string;
route?: string;
hide?: boolean;
auditLog?: {
permissions?: AuditLogPermissions[number][] | string[];
};
};
interface IResourceComponentsProps<
TCrudData = any,
TOptionsPropsExtends = { [key: string]: any },
> {
canCreate?: boolean;
canEdit?: boolean;
canDelete?: boolean;
canShow?: boolean;
name?: string;
initialData?: TCrudData;
options?: OptionsProps<TOptionsPropsExtends>;
}
interface IResourceComponents {
list?: React.FunctionComponent<IResourceComponentsProps<any, any>>;
create?: React.FunctionComponent<IResourceComponentsProps<any, any>>;
edit?: React.FunctionComponent<IResourceComponentsProps<any, any>>;
show?: React.FunctionComponent<IResourceComponentsProps<any, any>>;
}
interface IResourceItem extends IResourceComponents {
name: string;
label?: string;
route?: string;
icon?: ReactNode;
canCreate?: boolean;
canEdit?: boolean;
canShow?: boolean;
canDelete?: boolean;
options?: OptionsProps;
parentName?: string;
}
The
canCreate
,canShow
andcanEdit
properties are defined automatically if thecreate
,show
andedit
components are defined on theresources
property in<Refine>
.