Advanced data manipulation of a synchronized server state #4960
Replies: 2 comments 6 replies
-
I would generally question this. Why is it necessary? Server-state usually should have a single source of truth, which is the |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for looking into this issue. Before I jump into this, I wanted to note that the backend API I am connected to does not work in a way I could fetch, for example, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Welcome! I've probably picked the wrong tools for the job I am required to do, please help me decide.
Currently, I am using react-query to fetch server state - due to the Web's nature, the data is sent in a JSON format, an array at best. As the data is fetched, I am changing its shape completely by removing duplicates, creating instances of Classes, and finally building some Maps (of <string, Class> type) based on the results. All that happens in a select function of the useQuery hook.
The moment I'm done with all the above I have to push the results to a zustand-based state as I need an option to CRUD the Map as the application runs. There are no calls to the backend to modify the data. The way it's done is idiomatic:
Now, I've been tasked to enrich the data even more, with another server request that needs to fire right after the first one is done, which basically means I need to build a dependent query and modify my main data in a useEffect once again (2nd. useEffect).
It crossed my mind that all the actions above do not have to, and probably shouldn't be, placed in a React component. It's basically a lot of unnecessary actions (causing rerenders) that could have been done behind the stage. And since I can't write to my store in a useQuery hook, I am leaning towards RTK Query which, if I am understanding it right, could do just that. Can anybody push me in the right direction? Is my idea about RTKQ correct?
Beta Was this translation helpful? Give feedback.
All reactions