Skip to content

Commit 820c32d

Browse files
authored
Merge pull request #115 from invertase/next
2 parents 7056b89 + dcf569d commit 820c32d

File tree

245 files changed

+15503
-31259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+15503
-31259
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 50 deletions
This file was deleted.

.firebaserc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
{}
1+
{
2+
"projects": {
3+
"default": "demo-project"
4+
},
5+
"targets": {},
6+
"etags": {}
7+
}

.github/workflows/testing.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/tests.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- next
7+
pull_request:
8+
branches:
9+
- next
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
# Checkout the repository
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@v4
21+
with:
22+
version: 9
23+
run_install: false # We'll do this later
24+
25+
# Setup Node.js with pnpm
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: 'pnpm'
31+
32+
# Install all dependencies at the root
33+
- name: Install dependencies (pnpm)
34+
run: pnpm install
35+
36+
- name: Start Firebase Emulator Suite
37+
uses: invertase/[email protected]
38+
with:
39+
emulators: 'auth,firestore,functions,storage,database,dataconnect'
40+
41+
- name: Verify Running Emulators
42+
run: |
43+
curl --silent http://localhost:4400/emulators | jq 'keys[]'
44+
45+
# Determine which packages have changed
46+
- name: Determine changed packages
47+
id: changes
48+
uses: dorny/paths-filter@v2
49+
with:
50+
filters: |
51+
react:
52+
- 'packages/react/**'
53+
54+
# Run tests for the React package if it has changed
55+
- name: Run React Tests
56+
if: steps.changes.outputs.react == 'true'
57+
run: pnpm vitest --dom 'packages/react'
58+
59+
# Run tests for the Vue package if it has changed
60+
# - name: Run Vue Tests
61+
# if: steps.changes.outputs.vue == 'true'
62+
# run: pnpm --filter vue test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ dist
1010

1111
functions/lib/**/*.js
1212
functions/lib/**/*.js.map
13+
14+
# Firebase cache
15+
.firebase/

.prettierignore

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 52 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,76 @@
11
> [!IMPORTANT]
2-
> This project is currently undergoing a overhaul, to support TanStack v5 - this includes a package restructuring, and enables support for other web frameworks!
2+
> This project is currently a work in progress. Please check back soon for updates!
33
4-
<h1 align="center">React Query Firebase</h1>
4+
<h1 align="center">TanStack Query Firebase</h1>
55
<p align="center">
6-
<span>A set of <a href="https://react-query.tanstack.com">React Query</a> hooks integrating with <a href="https://firebase.google.com/">Firebase</a>.</span>
6+
<span>A set of <a href="https://tanstack.com/query/latest">TanStack Query</a> hooks integrating with <a href="https://firebase.google.com/">Firebase</a>.</span>
77
</p>
88
<p align="center">
99
<span><a href="#installation">Installation</a> &bull;
10-
<a href="https://react-query-firebase.invertase.dev/"> Documentation</a> &bull;
10+
<a href="https://invertase.docs.page/tanstack-query-firebase"> Documentation</a> &bull;
1111
<a href="/LICENSE.md">License</a></span>
1212
</p>
1313
<br />
1414

15-
React Query Firebase provides a set of easy to use hooks for handling asynchronous tasks with Firebase in your React application.
16-
17-
## Why should I use React Query Firebase?
18-
19-
- **Backed by React Query** - Unlike other solutions, hooks are built on top of [React Query](https://react-query.tanstack.com) which takes care of complex challenges
20-
such as caching, automatic refetching, realtime data subscriptions, pagination & infinite queries, mutations, SSR Support, data selectors, side effect handlers and more. You also get [DevTool](https://react-query.tanstack.com/devtools)
21-
support out of the box!
22-
- **Un-opinionated** - You provide the Query Keys, Configuration & Firebase instances, allowing for full control over how your data is integrated and cached. You can also roll it alongside any existing Firebase usage.
23-
- **Performant & Efficient** - Whether your queries are one-off or realtime, the library is designed to be performant and efficient. Data fetching is handled via [Queries](https://react-query.tanstack.com/guides/queries) and
24-
[Query Keys](https://react-query.tanstack.com/guides/query-keys), meaning components can share data throughout your application without needless database reads.
25-
- **Mutations** - Sign a user in, delete a document, run a transaction, log an event... React Query Firebase takes care of that for you via [Mutations](https://react-query.tanstack.com/guides/mutations), allowing you to focus
26-
on your application and not managing complex local loading & error states.
27-
- **Fully Typed** - The library is built with and has full compatibility with TypeScript.
28-
29-
> **Note**: The library supports the Firebase JS SDK v9 - [learn more about it here](https://firebase.googleblog.com/2021/08/the-new-firebase-js-sdk-now-ga.html)!
30-
31-
## Example
32-
33-
As an example, let's use a Firestore hooks to fetch a document & run a transaction whilst easily handling asynchronous state.
34-
35-
```tsx
36-
import {
37-
useFirestoreDocument,
38-
useFirestoreTransaction,
39-
} from "@react-query-firebase/firestore";
40-
import { doc } from "firebase/firestore";
41-
import { firestore } from "./config/firebase";
42-
43-
type Product = {
44-
name: string;
45-
price: number;
46-
};
47-
48-
function ProductPage({ id }: { id: string }) {
49-
// Create a Firestore document reference
50-
const ref = doc(firestore, "products", id);
51-
52-
// Query a Firestore document using useQuery
53-
const product = useFirestoreDocument<Product>(
54-
["product", id],
55-
ref,
56-
{
57-
// Subscribe to realtime changes
58-
subscribe: true,
59-
// Include metadata changes in the updates
60-
includeMetadataChanges: true,
61-
},
62-
{
63-
// Optionally handle side effects with React Query hook options
64-
onSuccess(snapshot) {
65-
console.log("Successfully fetched product ID: ", snapshot.id);
66-
},
67-
}
68-
);
69-
70-
// Run a Firestore transaction as Mutation using useMutation
71-
const like = useFirestoreTransaction(
72-
auth,
73-
async (tsx) => {
74-
const record = await tsx.get(ref);
75-
tsx.update(ref, {
76-
likes: record.data().likes + 1,
77-
});
78-
},
79-
{
80-
onError(error) {
81-
console.error("Failed to like product!", error);
82-
},
83-
}
84-
);
85-
86-
if (product.isLoading) {
87-
return <div>Loading...</div>;
88-
}
89-
90-
if (product.isError) {
91-
return <div>Failed to fetch product: {product.error.message}</div>;
92-
}
93-
94-
const snapshot = product.data; // DocumentSnapshot<Product>
95-
96-
return (
97-
<div>
98-
<h1>{snapshot.data().name}</h1>
99-
<button disabled={like.isLoading} onClick={() => like.mutate()}>
100-
Like Product!
101-
</button>
102-
{like.isError && <p>Failed to like product: {like.error.message}</p>}
103-
</div>
104-
);
105-
}
106-
```
15+
TanStack Query Firebase provides a set of hooks for handling asynchronous tasks with Firebase in your applications.
10716

108-
## Installation
17+
> Looking for React Query Firebase? Check out the [old branch](https://github.com/invertase/tanstack-query-firebase/tree/react-query-firebase).
10918
110-
If you haven't done so already, install `react`, `react-query` & `firebase` (v9):
19+
## Why use this library?
11120

112-
```bash
113-
npm i --save react react-query firebase
114-
```
21+
When managing Firebase’s asynchronous API calls within your application, state synchronization can become cumbersome in most applications. You will commonly find yourself handling loading states, error states, and data synchronization manually.
22+
23+
This library provides a hands-off approach to these problems, by leveraging the popular [TanStack Query](https://tanstack.com/query/latest) project. Out of the box, you get:
11524

116-
Before using this library, ensure React Query is setup on your project by following the [Installation](https://react-query.tanstack.com/quick-start) guide.
25+
- **Automatic Caching**: Avoid redundant Firebase calls with built-in caching.
26+
- **Out-of-the-box Synchronization**: TanStack Query keeps your UI in sync with the Firebase backend effortlessly.
27+
- **Background Updates**: Fetch and sync data seamlessly in the background without interrupting the user experience.
28+
- **Error Handling & Retries**: Get automatic retries on failed Firebase calls, with robust error handling baked in.
29+
- **Dev Tools for Debugging**: Leverage the React Query Devtools to gain insights into your data-fetching logic and Firebase interactions.
11730

118-
Next install one of the React Query Firebase packages, e.g:
31+
By combining Firebase with TanStack Query, you can make your app more resilient, performant, and scalable, all while writing less code.
32+
33+
## Installation
34+
35+
This project expects you have `firebase` installed as a peer dependency. If you haven't done so already, install `firebase`:
11936

12037
```bash
121-
npm i --save @react-query-firebase/firestore
38+
npm i --save firebase
12239
```
12340

124-
See below for a full list of available packages.
41+
Next, install specific packages for your framework of choice:
42+
43+
### React
12544

126-
## Packages
45+
```
46+
npm i --save @tanstack/react-query @tanstack-query-firebase/react
47+
```
12748

128-
- [`@react-query-firebase/analytics`](https://react-query-firebase.invertase.dev/analytics)
129-
- [`@react-query-firebase/auth`](https://react-query-firebase.invertase.dev/auth)
130-
- [`@react-query-firebase/database`](https://react-query-firebase.invertase.dev/database)
131-
- [`@react-query-firebase/firestore`](https://react-query-firebase.invertase.dev/firestore)
132-
- [`@react-query-firebase/functions`](https://react-query-firebase.invertase.dev/functions)
49+
See the [Documentation](https://invertase.docs.page/tanstack-query-firebase/react) for more information on how to use the library.
50+
51+
## Status
52+
53+
The status of the following Firebase services and frameworks are as follows:
54+
55+
- ✅ Ready for use
56+
- 🟠 Work in progress
57+
- () Not yet started
58+
59+
| Module | React | Vue | Solid | Angular | Svelte |
60+
|----------------|--:-:--|--:-:--|--:-:--|--:-:----|--:-:---|
61+
| analytics | | | | | |
62+
| app-check | | | | | |
63+
| auth | 🟠 | | | | |
64+
| database | | | | | |
65+
| data-connect || | | | |
66+
| firestore | 🟠 | | | | |
67+
| firestore/lite | | | | | |
68+
| functions | | | | | |
69+
| installations | | | | | |
70+
| messaging | | | | | |
71+
| performance | | | | | |
72+
| remote-config | | | | | |
73+
| vertexai | | | | | |
13374

13475
## License
13576

babel.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)