Skip to content

Commit

Permalink
Increase version
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio García committed Aug 10, 2021
1 parent 65357cc commit b779760
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { default as useMutation } from "./useMutation";
export { default as useQuery } from "./useQuery";
export { default as wrapRootComponent } from "./wrapRootComponent";
export { invalidateQuery } from "./utils";
31 changes: 1 addition & 30 deletions src/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,7 @@ import { setupServer } from "msw/node";
import { rest } from "msw";
import { useUnsweetenedMutation } from "./useMutation";
import { useUnsweetenedQuery } from "./useQuery";
import { QueryClient, useQueryClient as useRQQueryClient } from "react-query";
import { AnyFunction } from "./ts-helpers";

interface ExtendedQueryClient extends QueryClient {
invalidateQuery: (queryKey: AnyFunction) => void;
invalidateQueryKey: (queryKey: string) => void;
}

function useQueryClient(
...args: Parameters<typeof useRQQueryClient>
): ExtendedQueryClient {
const client = useRQQueryClient(...args) as ExtendedQueryClient;

client.invalidateQueryKey = function (queryKey: string) {
this.invalidateQueries(queryKey);
};
client.invalidateQuery = function (queryKey: AnyFunction) {
// This is not a arbitrary convertion. queryKey works differently between the TS world
// and the runtime world:
// - In the TS world, this is a function
// - In the runtime world, this is a string
const queryKeyAsString = queryKey as unknown as string;
this.invalidateQueryKey(queryKeyAsString);
};

client.invalidateQueryKey = client.invalidateQueryKey.bind(client);
client.invalidateQuery = client.invalidateQuery.bind(client);

return client;
}
import useQueryClient from "./useQueryClient";

let serverData: { numbers: Array<number> } = {
numbers: [],
Expand Down
33 changes: 33 additions & 0 deletions src/useQueryClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { QueryClient } from "react-query";
import { AnyFunction } from "./ts-helpers";
import { useQueryClient as useRQQueryClient } from "react-query";

interface ExtendedQueryClient extends QueryClient {
invalidateQuery: (queryKey: AnyFunction) => void;
invalidateQueryKey: (queryKey: string) => void;
}

function useQueryClient(
...args: Parameters<typeof useRQQueryClient>
): ExtendedQueryClient {
const client = useRQQueryClient(...args) as ExtendedQueryClient;

client.invalidateQueryKey = function (queryKey: string) {
this.invalidateQueries(queryKey);
};
client.invalidateQuery = function (queryKey: AnyFunction) {
// This is not a arbitrary convertion. queryKey works differently between the TS world
// and the runtime world:
// - In the TS world, this is a function
// - In the runtime world, this is a string
const queryKeyAsString = queryKey as unknown as string;
this.invalidateQueryKey(queryKeyAsString);
};

client.invalidateQueryKey = client.invalidateQueryKey.bind(client);
client.invalidateQuery = client.invalidateQuery.bind(client);

return client;
}

export default useQueryClient;

0 comments on commit b779760

Please sign in to comment.