How to run list function after create function
After running my create function, how do I trigger the list function to update the list?
9 Replies
Hi @script4559. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Hmm, I don't know enough to give you a confident answer yet. However, you might find what you're looking for in the refine documentation (https://refine.dev/docs).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@584066183989428345> kapa.ai is still learning and improving, please let us know how it did by reacting below
sensitive-blue•14mo ago
Hey @script4559, bot really disappointed me with this one 😅 If your resources match, it should automatically invalidate your list queries and they will trigger a refetch for the active (mounted) ones.
If the resources does not match, you can use the
useInvalidate
hook. Check out the docs here https://refine.dev/docs/core/hooks/data/use-invalidatenational-goldOP•14mo ago
😂😂
Oh
My resources do not match. I’m still having a hard time understanding the resources concept so I just use my endpoint url as the resource in the hooks instead of the ones passed into the <Refine> component at top level
Gotcha
I’ll check it out, thanks
sensitive-blue•14mo ago
Check these docs:
General Concepts > Resource Concept https://refine.dev/docs/guides-concepts/general-concepts/#resource-concept
Core API > Refine Component >
resources
https://refine.dev/docs/core/refine-component/#resources
the routes you pass to the action properties are for the router integration not for the API connection actually. These values will be used by the router features (such as inferring the current action, id and the resource from the route or navigation after form submissions and sidebar menus.) The one related with the data is just the name of the resource which will be passed to the data hook and then to the data provider's corresponding method.
Defining resources in the <Refine />
component will save you from explicitly passing the name of the resource every time in a specific resource route. For example, if you define a route with name posts
and if that has list: "/posts"
, when you are in the /posts
route your useTable
hooks will infer the resource name automatically. Check out the related section in the routing docs: https://refine.dev/docs/guides-concepts/routingnational-goldOP•14mo ago
so this is how what the docs portray basically @aliemirs
national-goldOP•14mo ago
@kapa.ai my api endpoint routes does not follow the standard REST Api way of having one route to hand all methods(post, get, put, etc.). How can I make data provider work for me?
Let me check the knowledge base for you. One moment! :books:
----------------------
Refine provides a way to handle non-standard REST API endpoints or connections with external resources through the
custom
method in the data provider. This method allows you to define custom parameters like URL, CRUD methods, and configurations. Here's an example of how you can define the custom
method:
Refine will consume this method using the useCustom
data hook.
If you want to modify the API endpoint path for a specific resource, you would need to modify your dataProvider
to handle this. You can extend the REST data provider and add your custom functions by overriding the methods of the data provider. The simplest way to do this is to use the Spread syntax. Here's an example:
In this example, @refinedev/simple-rest
uses the PATCH
HTTP method for update
, and it's changed to PUT
without forking the whole data provider.
For more detailed information, you can refer to the Refine documentation (https://refine.dev/docs/api-reference/core/providers/data-provider).
Sources:
- Discord support thread: How to define a custom api endpoint for a resource? (https://discord.com/channels/837692625737613362/1164078224062554222)
- Documentation > Docs > Core > Providers > Data Provider > Methods > custom (https://refine.dev/docs/core/providers/data-provider/#custom)
- Documentation > Docs > Packages > Data-providers > Simple REST > Customizing the data provider (https://refine.dev/docs/packages/data-providers/simple-rest/#customizing-the-data-provider)
- Discord support thread: dataprovider (https://discord.com/channels/837692625737613362/1134016650811818025)
- How to modify the api path corresponding to the data (https://github.com/refinedev/refine/discussions/3908)
- Discord support thread: Cache master call (https://discord.com/channels/837692625737613362/1132722419073818794)
- Discord support thread: Call useCustom on click (https://discord.com/channels/837692625737613362/1128261688618143756)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@584066183989428345> kapa.ai is still learning and improving, please let us know how it did by reacting below