-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of React Query for api calls #2074
Comments
Curious to hear how this contrasts with React 18+ In my (pedantic) opinion, one of the biggest drawbacks of our front end is that we employ an event-driven model instead of an action-driven one, such that we have a seemingly endless number of effect hooks. If we could diminish them (as well as prop stuffing) by using this, I'd be all in favor. |
Hey @anth-volk From what I understand, you're referring to how one useEffect can trigger others, complicating state management. React Query addresses these challenges effectively, providing numerous options that enhance both performance and usability. Additionally React docs itself strongly suggests not using useEffect at all or using it as the last resort to any problem We could begin with a module or a set of pages that you think are significantly impacted by the event-driven model. |
@bharateshwq Thanks for that rundown. I'd be completely onboard, and agreed, Much of the data fetching actually happens immediately on first load, and must be accessible from anywhere within the application, after which point routing is applied. I believe this initial fetch occurs within the Also, how does the usage of this library compare with the use of useEffect + Redux for state management with fetched data? |
Yeah i will send a pr on it, |
Hey @anth-volk , |
Precisely, this parameter triggers the creation of a new policy and returns a new policy ID for whenever a policy is renamed. This is because the app aims to display every created policy and no policy is "assigned" to any user, and thereby cannot allow an individual policy to be editable. |
Hey @anth-volk , |
@bharateshwq Thanks for letting me know, I will do. Just briefly glancing at this, it does look like a pretty significant improvement structurally. Off the top of my head, just a few questions/comments for you:
|
I completely understand the delays with the PRs. Regarding your second point, I've opened an issue about the workflow. I recognize that implementing changes will present challenges, but I genuinely believe it will be beneficial for maintaining the code in the long run. Issues with useEffect can arise unexpectedly, so addressing this proactively is important. Here's the workflow I propose: [link to issue]. Of course, I'm open to your thoughts on whether a different approach might be better. As for your third point, everything is currently functioning as intended with how the deployed application interacts with the backend. |
Thanks for this @bharateshwq. I totally understand, and I agree, I'll be sure to check out the workflow when I review. I will try to get around to this today, but am unsure if I'll be able to. It may have to be either tomorrow or Wednesday, depending on workload. And on the third point, glad to hear. I hadn't really checked deeply into the implementation, just wanted to highlight it, since I noticed the changes you had proposed. |
I think we should consider using React Query for our data fetching instead of useEffect.
Here's their docs https://tanstack.com/query/v3
Brief about it:
Caching: React Query automatically caches data, so we don’t have to worry about making the same requests over and over.
Optimistic Updates: It lets us update the UI instantly while waiting for the data, making things feel smoother.
Background Updates: Data can refresh in the background, keeping everything up to date without extra work.
Garbage Collection: It automatically cleans up unused data, which helps with performance.
-Easier State Management: It handles loading and error states for us, so we can write less code.
The text was updated successfully, but these errors were encountered: