Skip to content

Commit a2d2f1c

Browse files
jhuleattjustjish
andauthored
Support Firebase v9 (#369)
Co-authored-by: Sujish K Patel <[email protected]>
1 parent 80223d6 commit a2d2f1c

File tree

87 files changed

+3452
-3688
lines changed

Some content is hidden

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

87 files changed

+3452
-3688
lines changed

.all-contributorsrc

-43
This file was deleted.

.github/workflows/test.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ jobs:
100100
key: firebase_emulators
101101
- name: 'Download Artifacts'
102102
uses: actions/download-artifact@v2
103+
- name: Check available files/dirs
104+
run: ls -a
103105
- name: Expand Artifact
104106
run: |
105107
chmod +x reactfire-${{ github.run_id }}/unpack.sh
@@ -109,8 +111,8 @@ jobs:
109111
publish:
110112
runs-on: ubuntu-latest
111113
name: Publish (NPM)
112-
needs: test
113-
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
114+
needs: build
115+
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/modular-firebase' || github.event_name == 'release' }}
114116
steps:
115117
- name: Setup node
116118
uses: actions/setup-node@v2-beta

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ publish.sh
2626
unpack.sh
2727

2828
example/.parcel-cache/
29+
.firebaserc

README.md

+33-52
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
11
# ReactFire
22

3-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
3+
Hooks, Context Providers, and Components that make it easy to interact with
4+
Firebase.
45

5-
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
6+
---
67

7-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
8+
> **WARNING**: This branch is the work in progress for version 4 of ReactFire. [You can find version 3 here](https://github.com/firebaseextended/reactfire/tree/v3), if you're looking for documentation or to contribute to stable.
89
9-
Hooks, Context Providers, and Components that make it easy to interact with
10-
Firebase.
10+
---
1111

1212
## What is ReactFire?
1313

1414
- **Easy realtime updates for your function components** - Hooks
1515
like `useUser`and `useFirestoreCollection` let you easily subscribe to
1616
auth state, realtime data, and all other Firebase SDK events. Plus, they automatically unsubscribe when your component unmounts.
1717
- **Access Firebase libraries from any component** - Need the Firestore SDK? `useFirestore`. Remote Config? `useRemoteConfig`.
18-
- **Built-in Support for prefetching** - Decrease your load times by starting a connection to products like Firestore, Auth, or Realtime Database before the component that consumes that data is rendered with functions like `preloadUser`
19-
- **Safely configure Firebase libraries** - Libraries like Firestore and Remote Config require setting like `enablePersistence` to be set before any data fetches are made. This can be tough to support in React's world of re-renders. ReactFire gives you a trusted way to set these settings so you're sure they're set before anything else.
20-
21-
### Experimental [concurrent mode](https://reactjs.org/docs/concurrent-mode-suspense.html) features
22-
23-
- **Loading states handled by `<Suspense>`** - ReactFire's hooks throw promises
24-
that Suspense can catch. No more `isLoaded ?...` - let React
25-
[handle it for you](https://reactjs.org/docs/concurrent-mode-suspense.html).
26-
- **Faster initial page load times** - Load only the code you need, when you need it, with `useFirestore`, `useAuth`, `useRemoteConfig`, and more.
27-
- **Convenient components for common use cases** - Only want to render a component if a user is signed in? Wrap it in `<AuthCheck />`. Need to automatically instrument your `Suspense` load times with [RUM](https://firebase.google.com/docs/perf-mon)? Use `<SuspenseWithPerf />`.
18+
- **Safely configure Firebase libraries** - Libraries like Firestore and Remote Config require settings like `enablePersistence` to be set before any data fetches are made. This can be tough to support in React's world of re-renders. ReactFire gives you `useInitFirestore` and `useInitRemoteConfig` hooks that guarantee they're set before anything else.
2819

2920
## Install
3021

3122
```bash
3223
# npm
33-
npm install --save reactfire firebase
24+
npm install --save reactfire@exp firebase@exp
3425

3526
# or
3627

3728
# yarn
38-
yarn add reactfire firebase
29+
yarn add reactfire@exp firebase@exp
3930
```
4031

4132
Depending on your targeted platforms you may need to install polyfills. The most commonly needed will be [globalThis](https://caniuse.com/#search=globalThis) and [Proxy](https://caniuse.com/#search=Proxy).
@@ -46,33 +37,32 @@ Depending on your targeted platforms you may need to install polyfills. The most
4637
- Advanced: If you're using Concurrent Mode, check out the [Concurrent Mode quickstart](./docs/quickstart-concurrent-mode.md)
4738
- [**Common Use Cases**](./docs/use.md)
4839
- [**API Reference**](./docs/reference)
40+
- [**v3 -> v4 Upgrade Guide**](./docs/upgrade-guide.md)
4941

5042
## Example use
5143

5244
Check out the
53-
[live version on StackBlitz](https://stackblitz.com/fork/reactfire-sample)!
45+
[live version on StackBlitz](https://stackblitz.com/fork/reactfire-v4-sample)!
5446

5547
```jsx
56-
import React, { Component } from 'react';
48+
import React from 'react';
5749
import { render } from 'react-dom';
5850

59-
import 'firebase/firestore';
60-
import { FirebaseAppProvider, useFirestoreDocData, useFirestore } from 'reactfire';
51+
import { doc, getFirestore } from 'firebase/firestore';
52+
import { FirebaseAppProvider, FirestoreProvider, useFirestoreDocData, useFirestore, useFirebaseApp } from 'reactfire';
6153

6254
const firebaseConfig = {
63-
/* Add your config from the Firebase Console */
55+
/* Add in your config object from the Firebase console */
6456
};
6557

66-
function Burrito() {
67-
// easily access the Firestore library
68-
const burritoRef = useFirestore()
69-
.collection('tryreactfire')
70-
.doc('burrito');
58+
function BurritoTaste() {
59+
// access the Firestore library
60+
const burritoRef = doc(useFirestore(), 'tryreactfire', 'burrito');
7161

7262
// subscribe to a document for realtime updates. just one line!
7363
const { status, data } = useFirestoreDocData(burritoRef);
7464

75-
// easily check the loading status
65+
// check the loading status
7666
if (status === 'loading') {
7767
return <p>Fetching burrito flavor...</p>;
7868
}
@@ -81,15 +71,21 @@ function Burrito() {
8171
}
8272

8373
function App() {
74+
const firestoreInstance = getFirestore(useFirebaseApp());
8475
return (
85-
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
76+
<FirestoreProvider sdk={firestoreInstance}>
8677
<h1>🌯</h1>
87-
<Burrito />
88-
</FirebaseAppProvider>
78+
<BurritoTaste />
79+
</FirestoreProvider>
8980
);
9081
}
9182

92-
render(<App />, document.getElementById('root'));
83+
render(
84+
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
85+
<App />
86+
</FirebaseAppProvider>,
87+
document.getElementById('root')
88+
);
9389
```
9490

9591
---
@@ -104,24 +100,9 @@ render(<App />, document.getElementById('root'));
104100

105101
This repository is maintained by Googlers but is not a supported Firebase product. Issues here are answered by maintainers and other community members on GitHub on a best-effort basis.
106102

107-
## Contributors ✨
108-
109-
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
110-
111-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
112-
<!-- prettier-ignore-start -->
113-
<!-- markdownlint-disable -->
114-
<table>
115-
<tr>
116-
<td align="center"><a href="http://www.dfweb.no"><img src="https://avatars1.githubusercontent.com/u/45217974?v=4" width="100px;" alt=""/><br /><sub><b>w3bdesign</b></sub></a><br /><a href="https://github.com/FirebaseExtended/reactfire/commits?author=w3bdesign" title="Code">💻</a></td>
117-
<td align="center"><a href="http://prue.io"><img src="https://avatars0.githubusercontent.com/u/2992224?v=4" width="100px;" alt=""/><br /><sub><b>Scott Prue</b></sub></a><br /><a href="https://github.com/FirebaseExtended/reactfire/commits?author=prescottprue" title="Code">💻</a></td>
118-
<td align="center"><a href="http://git.io/jhuleatt"><img src="https://avatars0.githubusercontent.com/u/3759507?v=4" width="100px;" alt=""/><br /><sub><b>Jeff</b></sub></a><br /><a href="https://github.com/FirebaseExtended/reactfire/commits?author=jhuleatt" title="Code">💻</a></td>
119-
</tr>
120-
</table>
121-
122-
<!-- markdownlint-enable -->
123-
<!-- prettier-ignore-end -->
103+
### Extra Experimental [concurrent mode](https://reactjs.org/docs/concurrent-mode-suspense.html) features
124104

125-
<!-- ALL-CONTRIBUTORS-LIST:END -->
126-
127-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
105+
- **Loading states handled by `<Suspense>`** - ReactFire's hooks throw promises
106+
that Suspense can catch. No more `isLoaded ?...` - let React
107+
[handle it for you](https://reactjs.org/docs/concurrent-mode-suspense.html).
108+
- **Automatically instrument your `Suspense` load times** - Need to automatically instrument your `Suspense` load times with [RUM](https://firebase.google.com/docs/perf-mon)? Use `<SuspenseWithPerf />`.

build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ if [[ $GITHUB_REF =~ $TAG_TEST ]]; then
1111
NPM_TAG=latest
1212
fi;
1313
else
14-
OVERRIDE_VERSION=$(node -e "console.log(require('./package.json').version)")-canary.$SHORT_SHA
15-
NPM_TAG=canary
14+
OVERRIDE_VERSION=$(node -e "console.log(require('./package.json').version)")-exp.$SHORT_SHA
15+
NPM_TAG=exp
1616
fi;
1717

1818
npm --no-git-tag-version --allow-same-version -f version $OVERRIDE_VERSION

database.rules.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"rules": {
3+
".read": "true",
4+
".write": "true",
5+
"items": {
6+
".indexOn": "a"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)