Can we use different resources for detail and update?
I have a requirement where my resources details comes from
/endpoint
and I should update or patch to another api endpoint /s/endpoint
. So, how can I use one endpoint to fetch the detail data and while submitting a form send to a different endpoint?3 Replies
inc-lavender•2y ago
Hi @dipbazz,
For example, if you wanna update
categories
resource from post
resource, u can give resource
name to any data provider's hook. you can use this https://refine.dev/docs/api-reference/core/hooks/data/useUpdate/
resource: "/s/endpoint"
But if u need completly custom, you can use https://refine.dev/docs/api-reference/core/hooks/data/useCustomMutation/
but don't forget please, you should manually invalidate queries.
For example: https://refine.dev/docs/faq/#how-can-i-change-the-form-data-before-submitting-it-to-the-api
Instead of calling onFinish()
from useForm()
You can call useCustom
's mutation()
inland-turquoise•2y ago
I have used
useOne
to get the detail and useForm
with a different resource for a patch but now I have a problem with redirect. How can I redirect to a list page that has a different resource not same as useForm
.
What I have done is:
After submitting a form the page is redirected to s/posts
but I have a list of posts in /posts
so how to redirect to /posts
page after successful mutation?inc-lavender•2y ago
Unfortunately the redirect only goes to the resource used. You can change only view type.
list | show | edit
or you can disable with false
you can give redirect:false
to useForm()
, after onMutationSuccess
you can redirect programmaticly.
https://refine.dev/docs/api-reference/core/hooks/navigation/useNavigation/