T
TanStack12mo ago
rare-sapphire

Trigger refetch/rerender after setDefaultOptions

useEffect(() => {
client.setDefaultOptions({
queries: {
meta: {
workspace,
},
},
mutations: {
meta: {
workspace,
},
},
});

client.refetchQueries();
}, [workspace]);
useEffect(() => {
client.setDefaultOptions({
queries: {
meta: {
workspace,
},
},
mutations: {
meta: {
workspace,
},
},
});

client.refetchQueries();
}, [workspace]);
I would like to trigger a refetch of all queries when the workpace variable changes. Workspace is being passed in most api's as a custom header and fed into the api via react-queries meta object. The problem is that refetchQueries() does not have the updated meta object when refetching.
2 Replies
afraid-scarlet
afraid-scarlet12mo ago
I think your better off placing workspace into the queryKeys of the queries that need it, like ['queryId, workspace, ...otherOptions]. Would be annoying if it's like every query, might be worth making a factory function. I'm not sure of another way to do it if it's a truly global depenency. How is workspace updated? It would be better for that code to be in the event callback when workspace is changed.
sharp-indigo
sharp-indigo12mo ago
This, im doing this as well, i just pass a client_uuid into all my queries.

Did you find this page helpful?