-
|
Sometimes I want to use advanced usage of react-query with optimistic updates. export function useInviteMemberToOrganization() {
const queryClient = useQueryClient();
return useMutation(someFunctionThatCallsTheServer, {
onSuccess: (data, variables) => {
const queryKey = queryKeys.getQueryKey(variables);
queryClient.setQueryData<Array<SomeType>>(
queryKey,
(queriesData = []) => {
return getUpdatedData(queriesData, data)
}
);
},
});
}For example. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
since there is no correlation between the key and what's in the cache, you can't do this natively with RQ. You'd need to define a wrapper of some sorts that knows about the data structure for each key. I did some work in that regard waaay back for v2, maybe it is useful: https://gist.github.com/TkDodo/74051d3224358b8a7f2407630885cbda |
Beta Was this translation helpful? Give feedback.
since there is no correlation between the key and what's in the cache, you can't do this natively with RQ. You'd need to define a wrapper of some sorts that knows about the data structure for each key.
I did some work in that regard waaay back for v2, maybe it is useful: https://gist.github.com/TkDodo/74051d3224358b8a7f2407630885cbda