Closed jamesncox closed 3 years ago
Visit the preview URL for this PR (updated for commit db6ca1e):
https://tcl-23-shopping-list--pr24-jc-use-collection-in-fcbct6t3.web.app
(expires Sun, 09 May 2021 21:13:07 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
Thank you for doing this, James! Also, I appreciate the thorough explanation of the process you went through with this issue, and sharing the comparison of Redux to our use of Firestore in this instance.
Description
IMPORTANT! Only merge this PR once issue 8 (#9) has been merged! I created this branch off that branch. Next time I'll know to create a branch off
main
.This PR completely removes the REST-style GET request to the Firebase API, and instead takes advantage of the Firebase hook,
useCollection
, in bothList.js
andAddItem.js
. After discussing the issue with @skylerwshaw, I have a much better understanding how Firebase useCollection hook works, providing a constant down-stream of data. When we had the fetch inside ouruseEffect()
, we were not leveraging the power of Firebase via the useCollection hook.Related Issue
closes #23
Acceptance Criteria
This PR goes a different direction than the original issue. Having the connection to Firebase in
App.js
makes a lot of sense. But it causes more headaches/bugs than it solves, because before thetoken
is fully resolved in itsuseEffect()
the useCollection hook runs with an emptytoken
.So we definitely want to leverage
useCollection
but we need to have a persistedtoken
first. And because the way we route between eitherList.js
ORAddItem.js
, the connection to the database viauseCollection
will never be called simultaneously between the two components.@skylerwshaw helped me liken it to how Redux provides a central store of state for the whole app to access. Firestore is kind of like our central store, and we're reading from it similarly how you might request data from Redux central store in multiple components.
After all those considerations, I don't see it as a negative having
useCollection
called in two different components.Type of Changes
Updates
useEffect()
containg our.get()
request to Firestore.List.js
andAddItem.js
.Before
In
App.js
:After
Added to
List.js
andAddItem.js
:Testing Steps / QA Criteria
tcl-23-smart-shopping-list
git checkout main
git pull
git checkout jc-use-collection-instead-of-get
npm install
npm start