Custom CRUD operations
Can anyone point me towards resources/docs where I can learn about implementing custom crud operations. Like using useCreate outside of the
Create
view component.5 Replies
Hi @ansellmax. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Sure, I can guide you on how to implement custom CRUD operations in refine.
The
useCustom
data hook is used to consume the custom
method in refine. Here is an example of how to use it:
You can find more information about the useCustom
hook in the refine documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCustom/).
However, the information extracts provided do not contain specific examples of using useCreate
outside of the Create
view component. For more detailed information on this, I would recommend checking the official refine documentation or their API reference.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@585815815526285331> kapa.ai is still learning and improving, please let us how it did by reacting below
ambitious-aquaOP•2y ago
@kapa.ai I'm using Supabase. I just need to know the recommended implementations when calling things like
useCreate
explicitly instead of relying on the provided Create
view component.Let me check the knowledge base for you. One moment! :books:
----------------------
Sure, you can use the
useCreate
hook explicitly in your components to create new records. Here's an example of how you can use it:
In this example, mutate
is a method returned by useCreate
which expects values
and resource
as parameters. These parameters will be passed to the create
method from the dataProvider
as parameters. The resource
parameter is the name of the resource you want to create, and values
are the new data for the resource.
You can also customize the success notification that shows up when the data is fetched successfully. Here's how you can do it:
In this example, successNotification
is a function that returns a notification object. This function is called when the data is fetched successfully.
If you have more than one dataProvider
, you can specify which one to use with the dataProviderName
prop:
In this example, second-data-provider
is the name of the dataProvider
to use.
You can find more information about useCreate
in the refine documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCreate/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@585815815526285331> kapa.ai is still learning and improving, please let us how it did by reacting below