harsh-harlequin
harsh-harlequinβ€’2y ago

useDelete hook and useTable

Hi guys, i use useTable hook to fetch data and take only one element from list via id in initial filter This activity happens in drawer and then i close it i want to reset data in resource I try to use useDelete hook for this action but nothing works. It is strange because in useTable i use the same resource as in useDelete hook And another problem that was detected yesterday - drawer has prop "destroyOnClose" - i don't know why, but it doesn't work(
10 Replies
fascinating-indigo
fascinating-indigoβ€’2y ago
Hey @amounguluz, sorry for the issue. About the second one destroyOnClose it might be because we also send forceRender: true in props. Can you check if removing that helps with the destroyOnClose? For the first one, I'm not sure if I understood right, what do you mean with reset and can you please share a code sample on useDelete hook and how you're using it for your case πŸ™
harsh-harlequin
harsh-harlequinβ€’2y ago
one second)
harsh-harlequin
harsh-harlequinβ€’2y ago
here i fetch data and allow user to search company via id
No description
harsh-harlequin
harsh-harlequinβ€’2y ago
here i clean/ reset data from the same resource using mutate from useDelete
No description
fascinating-indigo
fascinating-indigoβ€’2y ago
Can you make sure the mutate is called and check the Network tab to see if there's any sent requests there? If so, is there also a request for the list of companies resource? Let's try to figure out if it's about invalidation of the query responses or something else in the useDelete πŸ€”
harsh-harlequin
harsh-harlequinβ€’2y ago
maybe i'am not sure about how to use this hook, but i just want to clear data that cached in state, that was fetched in resource 'company' at first time; for example in redux i can just dispatch action with empty array and replace my table data with this array. But how to do it here?)
fascinating-indigo
fascinating-indigoβ€’2y ago
Oh, I think useInvalidate is the one you're looking for (docs here: https://refine.dev/docs/api-reference/core/hooks/invalidate/useInvalidate/) You can just use it like
const invalidate = useInvalidate();

invalidate({
resource: "companies",
invalidates: ["list"]
});
const invalidate = useInvalidate();

invalidate({
resource: "companies",
invalidates: ["list"]
});
This will clear the query store and force useTable to fetch the data again
harsh-harlequin
harsh-harlequinβ€’2y ago
wow) is it real to not fetch data after invalidate?)
fascinating-indigo
fascinating-indigoβ€’2y ago
It should re-fetch automatically if there's an active useTable hook with the same resource. Are you having trouble with refetch? Or are you trying to disable refetch after invalidation? If so, I think you can do that by setting refineCoreProps.queryOptions.enabled to false before setting invalidate action, then it will wait until there's an active useTable with the resource to fetch the data again. Hey @amounguluz, we were discussing your issue with @core team and thought your issues might be related to mismatches in resources. We've identified several code smells in our codebase that might cause mismatches between hooks with custom resource props. Do you have resources with same name different route or nested resources? Is there any chance you can share your resources array with us (you can rename/hide the names and configuration if there are any sensitive info there but please keep the matching names as is πŸ™ )
harsh-harlequin
harsh-harlequinβ€’2y ago
yes for sure! tomorrow i'll prepare you sample) or for example i can call you and show this)