Created
July 9, 2019 05:39
-
-
Save brennancheung/a1ee4bab9ae9016c26f71c2c7e28a6bb to your computer and use it in GitHub Desktop.
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
export const useFirestoreCollectionQuery = (path, renderFn) => { | |
const [state, setState] = useState(null) | |
const collection = useRef(useFirestoreCollection(path)) | |
useEffect(() => { | |
console.log('useEffect') | |
return collection.current.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