Example use
Check out the
live version on StackBlitz!
import React from 'react';
import { render } from 'react-dom';
import { doc, getFirestore } from 'firebase/firestore';
import { FirebaseAppProvider, FirestoreProvider, useFirestoreDocData, useFirestore, useFirebaseApp } from 'reactfire';
const firebaseConfig = {
/* Add in your config object from the Firebase console */
};
function BurritoTaste() {
// access the Firestore library
const burritoRef = doc(useFirestore(), 'tryreactfire', 'burrito');
// subscribe to a document for realtime updates. just one line!
const { status, data } = useFirestoreDocData(burritoRef);
// check the loading status
if (status === 'loading') {
return <p>Fetching burrito flavor...</p>;
}
return <p>The burrito is {data.yummy ? 'good' : 'bad'}!</p>;
}
function App() {
const firestoreInstance = getFirestore(useFirebaseApp());
return (
<FirestoreProvider sdk={firestoreInstance}>
<h1>🌯</h1>
<BurritoTaste />
</FirestoreProvider>
);
}
render(
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
<App />
</FirebaseAppProvider>,
document.getElementById('root')
);