Fix: Cache event data queried from database #35
+71
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🍞 What's new in this PR
🥐 Description
Caching queried data from database
🥖 Screenshots
🥪 How to review
app/events/eventscache.tsx, app/events/page.tsx, app/events/[event_id]/page.tsx, components/MyEventCard/MyEventCard.tsx
Honestly I have no idea if I did this right. From what I was reading online, React's cache and useMemo aren't really meant for data querying, but rather are for intensive computation. I believe this method of doing it is ok though, nextjs advises using the React cache function when using a database directly.
Data is definitely getting cached, confirmed through console log messages in fetch functions. Only first time render takes a second. Renders after first render are so quick.
Big thing:
I am getting a GET 500 error upon rendering of the page, but it seems like all the data has been fetched correctly.
I notice that when I use a useEffect instead of useMemo, the error does not show, but the cached data is not used and instead querying functions are used. Not sure why I am getting this error. Am I using useMemo wrong?
🥧 Next steps
Handling when new data comes into the database.
Possible ideas:
🥞 Relevant links
🥨 Online sources
🥯 Related PRs
CC: @celinechoiii