Advanced data manipulation of a synchronized server state #3164
Replies: 1 comment 7 replies
-
I am a bit irritated. Do you have a need for RTK Query in the first place if all you want to do is copy it over into a Zustand store? It sounds like you could simply call |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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