Skip to main content
Version: 3.xx.xx

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​

KeyDescriptionTypeDefault
resourceNameOrRouteNameDetermines which resource to use for redirectionstringResource name that it reads from route
recordItemIdAdds id to the end of the URLBaseKeyRecord id that it reads from route

Return value​

DescriptionType
resourcesIResourceItem[]
resourceIResourceItem
resourceNamestring
idBaseKey

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 and canEdit properties are defined automatically if the create, show and edit components are defined on the resources property in <Refine>.