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.
flat-fuchsia•2y ago
If
refetch
is not the solution, you can follow this way.
rising-crimson•2y ago
Hey @yildirayunlu, Thanks for your response but I get the following error
flat-fuchsia•2y ago
Let me test it in a working project. @dipbazz
rising-crimson•2y ago
Yeah sure @yildirayunlu
robust-apricot•2y ago
@dipbazz sorry for the delay, we'll respond to you today.
flat-fuchsia•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.rising-crimson•2y ago
Yeah sure @yildirayunlu .
rising-crimson•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...
flat-fuchsia•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...
rising-crimson•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
sunny-green•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
sunny-green•2y ago
rising-crimson•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