Skip to content

Commit

Permalink
fix: pass in default context
Browse files Browse the repository at this point in the history
  • Loading branch information
fgnass committed Aug 10, 2022
1 parent e720074 commit edffc95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
defaultContext,
useMutation,
UseMutationOptions,
UseMutationResult,
Expand Down Expand Up @@ -40,7 +41,7 @@ export function mutation<Api extends { [k: string]: (...args: any) => any }>(
ApiData<T>,
Error,
ApiArgs<T>
>(mutationKey, mutationFn, opts);
>(mutationKey, mutationFn, { context: defaultContext, ...opts });

const fn = async (...args: ApiArgs<T>) => mutateAsync(args);
Object.assign(fn, mutation);
Expand Down
6 changes: 4 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
defaultContext,
useQuery,
useQueryClient,
UseQueryOptions,
QueryClient
QueryClient,
} from "@tanstack/react-query";

// REVISIT: The Updater type was exported in V3. Is there a better way to get hold of it?
Expand Down Expand Up @@ -34,9 +35,10 @@ export function query<Api extends Record<string, (...args: any) => any>>(
const result = useQuery<TQueryFnData, Error, TData>({
queryKey,
queryFn,
context: defaultContext,
...(queryOpts as any),
});
const queryClient = useQueryClient();
const queryClient = useQueryClient({ context: defaultContext });
return {
...result,
queryKey,
Expand Down

0 comments on commit edffc95

Please sign in to comment.