Skip to content

Instantly share code, notes, and snippets.

@AndrewAllison
Created June 7, 2020 11:56
Show Gist options
  • Save AndrewAllison/a4f98df66cf05b17b78fe2f069184eaf to your computer and use it in GitHub Desktop.
Save AndrewAllison/a4f98df66cf05b17b78fe2f069184eaf to your computer and use it in GitHub Desktop.
Example of using Firebase with React
import React, { useEffect } from 'react';
import { Link } from "@reach/router";
import { db } from "../_core/firebase";
const HomePage = () => {
const init = async () => {
await db.collection('customers')
.onSnapshot(function (doc) {
let count = 0;
doc.forEach(() => count = count + 1)
console.log("Current data: ", count);
});
};
useEffect(() => {
init().then()
}, []);
return (<div>
<Link to={'/make-payment'}>Make A Payment</Link>
</div>);
};
export default HomePage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment