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/8cebe9e8ffd6aa8761f0b3111d2ce115 to your computer and use it in GitHub Desktop.
Save brennancheung/8cebe9e8ffd6aa8761f0b3111d2ce115 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)
})
}, [collection])
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