genetic-orange
genetic-orange5mo ago

Dynamically adding resources

I want to create a dynamic list of resources available to the user at login time by fetching a list of their permissions from a backend server. Is there a way to add resources to the IResourceItem list provided to the <Refine> tag after its instantiation? Or to not provide a resources property to <Refine> initially and then set it later? The goal is to dynamically construct the menu options for a <ThemedLayoutV2> component as well as set the associated routes based on user permissions with a call to my data provider.
2 Replies
kapa.ai
kapa.ai5mo ago
Hi @MesbearizingMeat. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Refine's resources prop is used to define the routes for CRUD pages and is used by Refine hooks and components. However, based on the provided knowledge sources, there is no explicit mention of dynamically adding resources to the resources prop after the <Refine> component has been instantiated. Typically, the resources prop is defined when the <Refine> component is rendered, and it's an array of resource items. Each resource item specifies the path to all its pages, instead of the exact component to render. The component to render is now specified in the route definitions source (https://refine.dev/blog/refine-react-invoice-generator-5#series-wrap-up). For example, a typical resource object inside the resources array looks like this:
{
"name": "canvases",
"list": "/canvases",
"show": "/canvases/show/:id"
}
{
"name": "canvases",
"list": "/canvases",
"show": "/canvases/show/:id"
}
source (https://refine.dev/blog/refine-pixels-3#refine-s-resources-prop) And the routes for each page and resource are defined using the <Routes> and <Route> components from the react-router-dom package source (https://refine.dev/blog/react-crud-app-with-dynamic-form-ant-design#project-setup). However, there's no mention in the provided sources about dynamically adding or modifying the resources prop after the <Refine> component has been instantiated. For more detailed information or potential workarounds, you might want to check the official Refine documentation or reach out to the Refine community. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@224018850419572736> kapa.ai is still learning and improving, please let us know how it did by reacting below