Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. export const useFirestoreCollectionQuery = (path, renderFn) => {
  2. const [state, setState] = useState(null)
  3.  
  4. const collection = useRef(useFirestoreCollection(path))
  5.  
  6. useEffect(() => {
  7. console.log('useEffect')
  8. return collection.current.onSnapshot(snapshot => {
  9. const docs = snapshot.docs.map(x => x.data())
  10. setState(docs)
  11. })
  12. }, [collection])
  13.  
  14. return state === null ? <div>Loading...</div> : renderFn(state)
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement