variable-lime•3y ago
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•3y ago
If
refetch is not the solution, you can follow this way.
variable-limeOP•3y ago
Hey @yildirayunlu, Thanks for your response but I get the following error
rival-black•3y ago
Let me test it in a working project. @dipbazz
variable-limeOP•3y ago
Yeah sure @yildirayunlu
harsh-harlequin•3y ago
@dipbazz sorry for the delay, we'll respond to you today.
rival-black•3y 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.variable-limeOP•3y ago
Yeah sure @yildirayunlu .
variable-limeOP•3y 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•3y 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...
variable-limeOP•3y 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
stormy-gold•3y 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
stormy-gold•3y ago

variable-limeOP•3y 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
stormy-gold•3y ago
where did u console ?
Hey @dipbazz ,
Can you try like this?
const queryClient = useQueryClient();
queryClient.invalidateQueries(["custom-key"]);
variable-limeOP•3y 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
fair-rose•16mo ago
and over a year later, I have this same issue
and after spending over 5 hours, I landed on this comment, and then I got it solved
Quite strange that destructuring didn't work