Show get resource

I am trying to dynamically get the resource name of which current show/edit/list page how can I achieve this ?
2 Replies
kapa.ai
kapa.ai4w ago
Hi @koop_g. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To dynamically get the resource name of the current show/edit/list page in refine, you can use the useResource hook. This hook allows you to retrieve information about the current resource based on the route. Here's how you can use it:
import { useResource } from "@refinedev/core";

const MyComponent = () => {
const { resource } = useResource();

console.log(resource?.name); // This will log the current resource name

// Rest of your component logic
};
import { useResource } from "@refinedev/core";

const MyComponent = () => {
const { resource } = useResource();

console.log(resource?.name); // This will log the current resource name

// Rest of your component logic
};
The useResource hook returns an object that includes the resource property. This resource object contains information about the current resource, including its name. By using this hook, you can dynamically access the resource name regardless of whether you're on a show, edit, or list page. The hook automatically infers the resource information from the current route. For more detailed information and additional use cases, you can refer to the useResource API Reference. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@1327562833537400895> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?