Created
July 9, 2019 05:36
-
-
Save brennancheung/8cebe9e8ffd6aa8761f0b3111d2ce115 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 = 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