Skip to content

Instantly share code, notes, and snippets.

@brennancheung
Created July 9, 2019 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennancheung/7875b7dc8791d5d1944c24f65657483f to your computer and use it in GitHub Desktop.
Save brennancheung/7875b7dc8791d5d1944c24f65657483f to your computer and use it in GitHub Desktop.
export const useFirestoreCollectionQuery = (path, renderFn) => {
const [state, setState] = useState(null)
const collection = useFirestoreCollection(path)
useEffect(() => {
console.log('useEffect')
return collection.onSnapshot(snapshot => {
const docs = snapshot.docs.map(x => x.data())
setState(docs)
})
}, [])
return state === null ? <div>Loading...</div> : renderFn(state)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment