I’m a beginner in using Firebase’s Firestore database and I want to get feedback and input on the way I’m trying to implement a simple fetch & display.
Let’s say I have a collection of documents that represent each unit in a course that I want to render on the /courses page.
Unit 1
{
unitName: "Unit 1"
unitDesc: "this is description"
// info below is not needed in homepage
unitInfo: "asdfasdf"
unitImage: "https://image.com"
unitTags: ["tag1","tag2"]
}
Unit 2
{
unitName: "Unit 1"
unitDesc: "this is description"
// info below is not needed in homepage
unitInfo: "asdfasdf"
unitImage: "https://image.com"
unitTags: ["tag1","tag2"]
}
This is how I vision my project to work.
/courses
page: fetch and render a list of units that showunitName
fieldunitDesc
field. Notice how I do not need to fetch other fields to render this page, but I still need to because I will be accessing the entire document for every unit in the collection- You click the unit button and it will redirect you to
/courses/unit1
page. I am not sure if there’s a way to ‘bring’ information from the initial fetched data through the redirect process into a different URL (other than fetching info again on redirected URL) /courses/unit1
page: you see unit information onunitInfo
,unitImage
, andunitTags
. I plan to fetch the single unit document again to render on this page.
I have a basic idea of how to implement this, but I feel there is a much better and more efficient way to achieve this. My current logic has flaws:
- when I wish to render the list of units via fetching collection, I need to fetch every single field even if I don’t need them.
- I need to fetch a single unit document once again when I’m redirected to
/courses/unit-n
I’m asking for any kind of input and/or feedback on my approach, and if there’s a better simpler way to achieve this! Thanks a lot :)