How to invalidate a custom query of `useCustom`?
I want to invalidate a custom query that I have fetched using a
useCustom
hook based on a useDrawerForm
successful mutation.
For example: I have a custom query as
And my drawer form as
20 Replies
Hi, I am refine support bot :wave:. I am here to help you with your question. I searched for the answer to your question in the refine documentation and found an answer! 🏆
Answer: You can invalidate a custom query fetched using a
Answer: You can invalidate a custom query fetched using a
useCustom
hook based on a useDrawerForm
successful mutation by using the useInvalidate
hook.
SOURCES: ./docs/api-reference/core/hooks/invalidate/useInvalidate.md, ./docs/api-reference/mantine/hooks/form/useForm.md
Note: If this is the answer you need, then we are very lucky. If not, please wait for someone from the refine core team or the community to try to help you.
rival-black•2y ago
If
refetch
is not the solution, you can follow this way.
genetic-orange•2y ago
Hey @yildirayunlu, Thanks for your response but I get the following error
rival-black•2y ago
Let me test it in a working project. @dipbazz
genetic-orange•2y ago
Yeah sure @yildirayunlu
other-emerald•2y ago
@dipbazz sorry for the delay, we'll respond to you today.
rival-black•2y ago
Hi @dipbazz , sorry for the late reply. I tried again today and got the same error. Could you please open an issue? Let's see what we can do.
We can add this property to the
useInvalide
hook.genetic-orange•2y ago
Yeah sure @yildirayunlu .
genetic-orange•2y ago
Here is an issue https://github.com/refinedev/refine/issues/3671
GitHub
[BUG] Invalidating custom queries using custom querykey raised Type...
Describe the bug While trying to invalidate a query using a custom queryKey I got an error as TypeError: this is undefined. Steps To Reproduce First create a custom query with a custom queryKey. co...
rival-black•2y ago
Thank you for your contribution 🚀
Hey @dipbazz ,
We've fixed it this issue 🥳 https://github.com/refinedev/refine/issues/3671#issuecomment-1470685833
GitHub
[BUG] Invalidating custom queries using custom querykey raised Type...
Describe the bug While trying to invalidate a query using a custom queryKey I got an error as TypeError: this is undefined. Steps To Reproduce First create a custom query with a custom queryKey. co...
genetic-orange•2y ago
Hey @Omer, I have tested with the latest version of refine. But still get the same error. Is there anything that I missed? I am using
I am using a custom query using
useCustom
with the query key and invalidating the query on my useDrawerForm
onMutationSuccess
, So my code in gist looks like
generous-apricot•2y ago
i`m working perfectly with new refine/core latest
"@chakra-ui/react": "^2.5.1",
"@hookform/resolvers": "^2.9.11",
"@next/font": "^13.1.6",
"@refinedev/chakra-ui": "latest",
"@refinedev/cli": "latest",
"@refinedev/core": "latest",
try to update npm update @refinedev/core
const { data } = useCustom<IRoles, HttpError>({
url: 'roles',
method: 'get',
config: {
query: {
start: pageIndex,
end: pageSize,
},
},
queryOptions: {
queryKey: ['roles', pageIndex, pageSize],
keepPreviousData: true,
},
});
this is my custom queryKey and working perfectly
generous-apricot•2y ago
![No description](https://cdn.answeroverflow.com/1085771859766824990/image.png)
genetic-orange•2y ago
I guess the invalidate part is working in my case as well, because the response value is updated for my query. But the problem is I still get the error on console as