Skip to content

Commit b863eed

Browse files
authored
[WIP] Concurrent Mode! (#170)
* Move sample-simple to Concurrent Mode * Preload a query and lazy import Firestore * more work on async/preloading * demonstrate useTransition * Update docs * add note about experimental react build * Update rollup config Now that we're doing lazy imports with multiple chunks, rollup needs to output to a directory * docs fixes * lazy import the rest of the SDKs * remove some extra imports * remove some extra imports
1 parent 2c9ad08 commit b863eed

File tree

22 files changed

+770
-221
lines changed

22 files changed

+770
-221
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ reactfire/firestore-debug.log
1515
reactfire/pub/**
1616
pub
1717
yarn-error.log
18+
reactfire/database-debug.log

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ to interact with Firebase.
55

66
> If you're looking for docs for the _deprecated_ ReactFire v1 (the one that uses mixins), click [here](https://github.com/FirebaseExtended/reactfire/tree/v1.0.0)
77
8+
**Status: Alpha**. ReactFire is meant for React Concurrent Mode, which is only available in [experimental React builds](https://reactjs.org/docs/concurrent-mode-adoption.html#installation).
9+
810
## What is ReactFire?
911

1012
- **Easy realtime updates for your function components** - Reactfire's hooks, like `useFirestoreCollection` and `useUser`, let you easily subscribe to events, and automatically unsubscribe when your component unmounts.
1113
- **Loading states handled by `<Suspense>`** - Reactfire's hooks throw promises that Suspense can catch. No more `isLoaded ?...` - let React [handle it for you](https://reactjs.org/blog/2018/11/27/react-16-roadmap.html#react-166-shipped-the-one-with-suspense-for-code-splitting).
1214
- **Dead-simple Real User Monitoring (RUM)** - Easily enable Firebase Performance Monitoring's [automatic traces](https://firebase.google.com/docs/perf-mon/automatic-web), and instrument your Suspenseful loads with Reactfire's `<SuspenseWithPerf>` component
1315

14-
Status: Alpha
15-
1616
## Install
1717

1818
```bash
@@ -34,33 +34,29 @@ import { render } from 'react-dom';
3434
import './style.css';
3535
import {
3636
FirebaseAppProvider,
37-
useFirestoreDoc,
38-
useFirebaseApp,
37+
useFirestoreDocData,
3938
SuspenseWithPerf
4039
} from 'reactfire';
4140

4241
import 'firebase/performance';
43-
import 'firebase/firestore';
4442

4543
const firebaseConfig = {
4644
/* add your config object from the Firebase console */
4745
};
4846

4947
function Burrito() {
50-
// create a ref
51-
const firebaseApp = useFirebaseApp();
52-
const burritoRef = firebaseApp
53-
.firestore()
48+
// lazy load the Firestore SDK and create a ref
49+
const burritoRef = useFirestore()
5450
.collection('tryreactfire')
5551
.doc('burrito');
5652

5753
// subscribe to the doc. just one line!
5854
// throws a Promise for Suspense to catch,
5955
// and then streams live updates
60-
const burritoDoc = useFirestoreDoc(burritoRef);
56+
const burrito = useFirestoreDocData(burritoRef);
6157

6258
// get the value from the doc
63-
const isYummy = burritoDoc.data().yummy;
59+
const isYummy = burrito.yummy;
6460

6561
return <p>The burrito is {isYummy ? 'good' : 'bad'}!</p>;
6662
}

docs/quickstart.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,11 @@ npm install firebase reactfire@canary
7777

7878
## 5. Modify `src/App.js`
7979

80-
1. Import `firebase/firestore` as well as the `useFirestoreDoc` and `useFirebaseApp` hooks
80+
1. Import the `useFirestoreDocData` and `useFirestore` hooks
8181

8282
```js
8383
//...
84-
import 'firebase/firestore';
85-
import {
86-
useFirestoreDoc,
87-
useFirebaseApp,
88-
SuspenseWithPerf
89-
} from 'reactfire';
84+
import { useFirestoreDocData, useFirestore } from 'reactfire';
9085
//...
9186
```
9287

@@ -95,18 +90,19 @@ npm install firebase reactfire@canary
9590
```jsx
9691
//...
9792
function Burrito() {
98-
// create a ref
99-
const firebaseApp = useFirebaseApp();
100-
const burritoRef = firebaseApp
101-
.firestore()
93+
// lazy load the Firestore SDK
94+
const firestore = useFirestore();
95+
96+
// create a document reference
97+
const burritoRef = firestore()
10298
.collection('tryreactfire')
10399
.doc('burrito');
104100

105101
// subscribe to the doc. just one line!
106-
const burritoDoc = useFirestoreDoc(burritoRef);
102+
const burrito = useFirestoreDocData(burritoRef);
107103

108104
// get the value from the doc
109-
const isYummy = burritoDoc.data().yummy;
105+
const isYummy = burrito.yummy;
110106

111107
return <p>The burrito is {isYummy ? 'good' : 'bad'}</p>;
112108
}
@@ -115,7 +111,7 @@ npm install firebase reactfire@canary
115111

116112
1. Render your component inside of a `Suspense` tag
117113

118-
> We need to do this because `useFirestoreDoc` throws a Promise while it is waiting for a response from Firestore. Suspense will catch the Promise and render `fallback` until the Promise is resolved.
114+
> We need to do this because `useFirestoreDocData` throws a Promise while it is waiting for a response from Firestore. Suspense will catch the Promise and render `fallback` until the Promise is resolved.
119115
120116
Replace the `App` function with the following:
121117

0 commit comments

Comments
 (0)