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
19 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.
wise-white•2y ago
If
refetch
is not the solution, you can follow this way.
provincial-silver•2y ago
Hey @yildirayunlu, Thanks for your response but I get the following error
wise-white•2y ago
Let me test it in a working project. @dipbazz
provincial-silver•2y ago
Yeah sure @yildirayunlu
extended-salmon•2y ago
@dipbazz sorry for the delay, we'll respond to you today.
wise-white•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.provincial-silver•2y ago
Yeah sure @yildirayunlu .
provincial-silver•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...
wise-white•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...
provincial-silver•17mo 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
ratty-blush•17mo 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
ratty-blush•17mo ago
![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1085771859766824990/image.png)
provincial-silver•17mo 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
ratty-blush•17mo ago
where did u console ?
Hey @dipbazz ,
Can you try like this?
const queryClient = useQueryClient();
queryClient.invalidateQueries(["custom-key"]);
provincial-silver•17mo ago
Hey @Omer, that did work. Can I know the reason behind why it didn't work while destructuring
invalidateQueries
🤔No, I don't know 🙂 It's strange haha