PrimeAcademy / shawl-syllabus

1 stars 2 forks source link

Trouble understanding useEffect / useSelector timing #10

Closed ozzythecoder closed 1 year ago

ozzythecoder commented 1 year ago

Description

Your Name August / Ozzy

What do you want to happen? I want my pages' info to persist on page refresh.

What is actually happening? In useEffect, I send a dispatch to fetch data and set it to my reducers. But the reducers don't have time to finish setting before my local variables try to access their data, which leaves me with (depending on my method) nothing, or an error that my reducer returned undefined.

Screenshots / Code Snippets

Screen Shot 2023-01-06 at 1 56 50 PM Screen Shot 2023-01-06 at 1 57 26 PM

The thisEvent variable is undefined when being sent in the SET_EVENT_TO_SUBMIT dispatch, which is what confuses me.

What did you try? Who did you ask?

I searched google and stackoverflow for explanations on why dispatch could be slow, or reducers could be too fast, as well as just general information on how to maintain info on page refresh. No dice; they went very in depth on class components, which we haven't covered. I also spoke with Andrew and Paolo about this. Paolo and I tried a few different things, including a second useEffect hook that listens for changes in thisEvent, but nothing solved the underlying problem. Andrew and I also tried a few things; he mentioned that he needed to write a new query that searched for his data by ID, rather than querying all data and filtering it with javascript, which is what I'm currently doing. The issue with that is that my approach works in other parts of my app, but not here.

What branch is your code on? Did you git push?

github.com/ozzythepainter/

When was the last time you took a break?

This has been an issue since yesterday, and has persisted even after multiple breaks, meals and naps.

DoctorHowser commented 1 year ago

refactoring to do a GET WHERE for the page instead of get all and filter.