Created
June 7, 2020 11:56
-
-
Save AndrewAllison/a4f98df66cf05b17b78fe2f069184eaf to your computer and use it in GitHub Desktop.
Example of using Firebase with React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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