Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to @tanstack/react-query (react-query v4) #61

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist

functions/lib/**/*.js
functions/lib/**/*.js.map
packages/**/*.tgz
2 changes: 1 addition & 1 deletion docs/auth/id-token.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Imagine we've got a custom `useApiRequest` hook within our application, using th
token before the request and attach it to the API request.

```js
import { useQueryClient, useQuery } from "react-query";
import { useQueryClient, useQuery } from "@tanstack/react-query";

function useApiRequest(url) {
const client = useQueryClient();
Expand Down
2 changes: 1 addition & 1 deletion examples/auth-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"firebase": "^9.1.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-query": "^3.23.2",
"@tanstack/react-query": "^4.2.1",
"react-scripts": "5.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/auth-basic/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import { QueryClient, QueryClientProvider } from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";

import { signInAnonymously, signOut } from "firebase/auth";
import { useAuthUser } from "@react-query-firebase/auth";
Expand Down
2 changes: 1 addition & 1 deletion examples/functions-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"firebase": "^9.1.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-query": "3.19.0",
"@tanstack/react-query": "^4.2.1",
"react-scripts": "4.0.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions examples/functions-basic/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
import ReactDOM from "react-dom";
import { QueryClient, QueryClientProvider } from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";

import {
useFunctionsQuery,
useFunctionsCall,
} from "@react-query-firebase/functions";
import { functions } from "./firebase";
import { useQueryClient } from "react-query";
import { useQueryClient } from "@tanstack/react-query";

const queryClient = new QueryClient();

Expand Down
974 changes: 510 additions & 464 deletions functions/yarn.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"keywords": [
"react",
"react-query",
"@tanstack/react-query",
"firebase",
"hooks"
],
Expand All @@ -17,6 +18,7 @@
"@babel/preset-env": "^7.15.6",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@tanstack/react-query": "^4.2.1",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react-hooks": "^7.0.2",
"@types/jest": "^27.0.1",
Expand All @@ -41,7 +43,6 @@
"prettier": "^2.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-query": "^3.23.2",
"react-test-renderer": "^18.2.0",
"rimraf": "^3.0.2",
"rollup": "^2.63.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
"build": "npm run clean && rollup -c",
"prepublish": "npm run build",
"clean": "rimraf dist",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"pack": "npm pack"
},
"author": "",
"license": "Apache-2.0",
"peerDependencies": {
"firebase": "^9.0.1",
"react": "^16.8.0 || ^17.0.0 || ^18.2.0",
"react-query": "^3.23.2"
"@tanstack/react-query": "^4.2.1"
}
}
1 change: 1 addition & 0 deletions packages/analytics/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export default {
},
],
plugins: [typescript()],
external: ['firebase/analytics', '@tanstack/react-query']
};
2 changes: 1 addition & 1 deletion packages/analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useQuery,
UseQueryOptions,
UseQueryResult,
} from "react-query";
} from "@tanstack/react-query";

export function useAnalyticsIsSupported(
key: QueryKey,
Expand Down
15 changes: 7 additions & 8 deletions packages/auth/__test__/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { QueryClient, QueryClientProvider, setLogger } from "react-query";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { initializeApp } from "firebase/app";
import {
getAuth,
Expand All @@ -9,13 +9,6 @@ import {
createUserWithEmailAndPassword,
} from "firebase/auth";

setLogger({
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => null,
});

let emulatorsStarted = false;

export function genId(): string {
Expand Down Expand Up @@ -47,6 +40,12 @@ export function init(): any {
cacheTime: 0,
},
},
logger: {
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => null,
},
});

const wrapper = ({ children }) => (
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/__test__/useAuthUser.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { QueryClient } from "react-query";
import { QueryClient } from "@tanstack/react-query";
import { renderHook, act, cleanup } from "@testing-library/react-hooks";
import { Auth, UserCredential } from "firebase/auth";
import { genId, init, signIn } from "./helpers";
Expand Down
5 changes: 3 additions & 2 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
"build": "npm run clean && rollup -c",
"prepublish": "npm run build",
"clean": "rimraf dist",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"pack": "npm pack"
},
"author": "",
"license": "Apache-2.0",
"peerDependencies": {
"firebase": "^9.0.1",
"react": "^16.8.0 || ^17.0.0 || ^18.2.0",
"react-query": "^3.23.2"
"@tanstack/react-query": "^4.2.1"
}
}
6 changes: 6 additions & 0 deletions packages/auth/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ export default {
},
],
plugins: [typescript()],
external: [
'@tanstack/react-query',
'firebase/auth',
'@firebase/auth',
'react'
]
};
2 changes: 1 addition & 1 deletion packages/auth/src/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
useMutation,
UseMutationOptions,
UseMutationResult,
} from "react-query";
} from "@tanstack/react-query";

export function useAuthApplyActionCode(
auth: Auth,
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/useAuthFetchSignInMethodsForEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
useQuery,
UseQueryOptions,
UseQueryResult,
} from "react-query";
} from "@tanstack/react-query";
import { Auth, fetchSignInMethodsForEmail, AuthError } from "firebase/auth";

export function useAuthFetchSignInMethodsForEmail(
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/useAuthGetRedirectResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
useQuery,
UseQueryOptions,
UseQueryResult,
} from "react-query";
} from "@tanstack/react-query";
import {
Auth,
AuthError,
Expand Down
8 changes: 6 additions & 2 deletions packages/auth/src/useAuthIdToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*
*/
import { QueryKey, UseQueryOptions, UseQueryResult } from "react-query";
import {
QueryKey,
UseQueryOptions,
UseQueryResult,
} from "@tanstack/react-query";
import { Auth, AuthError, IdTokenResult } from "firebase/auth";
import { useSubscription } from "../../utils/src/useSubscription";

Expand All @@ -37,7 +41,7 @@ export function useAuthIdToken<R = { token: IdTokenResult }>(

return useSubscription<{ token: IdTokenResult }, AuthError, R>(
queryKey,
"useAuthIdToken",
["useAuthIdToken"],
subscribeFn,
options
);
Expand Down
8 changes: 6 additions & 2 deletions packages/auth/src/useAuthUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*
*/
import { QueryKey, UseQueryOptions, UseQueryResult } from "react-query";
import {
QueryKey,
UseQueryOptions,
UseQueryResult,
} from "@tanstack/react-query";
import { Auth, AuthError, NextOrObserver, User } from "firebase/auth";
import { useSubscription } from "../../utils/src/useSubscription";

Expand All @@ -28,7 +32,7 @@ export function useAuthUser<R = User>(

return useSubscription<User, AuthError, R>(
queryKey,
"useAuthUser",
["useAuthUser"],
subscribeFn,
options
);
Expand Down
15 changes: 7 additions & 8 deletions packages/database/__test__/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import React from "react";
import { QueryClient, QueryClientProvider, setLogger } from "react-query";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { initializeApp } from "firebase/app";
import { connectDatabaseEmulator, getDatabase } from "firebase/database";

setLogger({
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => null,
});

let emulatorsStarted = false;

export function genId(): string {
Expand Down Expand Up @@ -37,6 +30,12 @@ export function init(): any {
cacheTime: 0,
},
},
logger: {
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => null,
},
});

const wrapper = ({ children }) => (
Expand Down
2 changes: 1 addition & 1 deletion packages/database/__test__/useDatabaseMutation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { QueryClient } from "react-query";
import { QueryClient } from "@tanstack/react-query";
import { renderHook } from "@testing-library/react-hooks";
import { genId, init } from "./helpers";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/database/__test__/useDatabaseSnapshot.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { QueryClient } from "react-query";
import { QueryClient } from "@tanstack/react-query";
import { renderHook } from "@testing-library/react-hooks";
import { genId, init } from "./helpers";
import { useDatabaseSnapshot, useDatabaseValue } from "../src";
Expand Down
5 changes: 3 additions & 2 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
"build": "npm run clean && rollup -c",
"prepublish": "npm run build",
"clean": "rimraf dist",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"pack": "npm pack"
},
"author": "",
"license": "Apache-2.0",
"peerDependencies": {
"firebase": "^9.0.1",
"react": "^16.8.0 || ^17.0.0 || ^18.2.0",
"react-query": "^3.23.2"
"@tanstack/react-query": "^4.2.1"
}
}
6 changes: 6 additions & 0 deletions packages/database/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ export default {
},
],
plugins: [typescript()],
external: [
'firebase/database',
'react',
'@tanstack/react-query',
'@firebase/database'
]
};
2 changes: 1 addition & 1 deletion packages/database/src/useDatabaseMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useMutation,
UseMutationOptions,
UseMutationResult,
} from "react-query";
} from "@tanstack/react-query";
import {
DatabaseReference,
remove,
Expand Down
6 changes: 5 additions & 1 deletion packages/database/src/useDatabaseSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*
*/
import { QueryKey, UseQueryOptions, UseQueryResult } from "react-query";
import {
QueryKey,
UseQueryOptions,
UseQueryResult,
} from "@tanstack/react-query";
import { DatabaseReference, onValue, DataSnapshot } from "firebase/database";
import { useCallback } from "react";
import { useSubscription } from "../../utils/src/useSubscription";
Expand Down
15 changes: 7 additions & 8 deletions packages/firestore/__test__/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@

import * as React from "react";
import axios from "axios";
import { QueryClient, QueryClientProvider, setLogger } from "react-query";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { initializeApp } from "firebase/app";
import { getFirestore, connectFirestoreEmulator } from "firebase/firestore";

setLogger({
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => null,
});

let emulatorsStarted = false;

export function genId(): string {
Expand Down Expand Up @@ -58,6 +51,12 @@ export function init(): any {
cacheTime: 0,
},
},
logger: {
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => null,
},
});

const wrapper = ({ children }) => (
Expand Down
Loading