-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
setQueryData slow with large data sets #1633
Comments
This might be due to react-query's however, I would advise against mixing client state with server state and manipulating the query in the cache directly. The idea is that the data you see is just a borrowed "view" of the actual server state, so the client does not own it. If a background update happens, or another component mounts that also uses this query, the data will be re-fetched and you will "loose" your client side sorting. I think a good alternative would be to keep server and client state separate. In your case, that would mean:
This could be nicely abstracted in a custom hook, something like:
You can use this like so in your component:
if the server data updates - it will be sorted. if the user changes the sorting - it will be sorted. I've made the experience that this approach works very well in most cases. |
Thanks for this great reply. Thought I might have been thinking about it incorrectly. I'll give that a shot. |
We are experiencing this issue on We are calling |
I'm sorry to say this is still an issue, even without |
Describe the bug
This may be a performance question, or maybe I need a paradigm shift.
I have a large query that comes back with several mb worth of data, for a table that gets frequently sorted. When I sort the data, and call
queryClient.setQueryData()
with the new sorted rows, it takes around half a second to complete. I've tried to break the data out into React state, and when I do that, it sorts in 10ms- but getting React state to sync nicely with React Query is challenging.In my profiler, I see quite a bit of time being taken by "replaceEqualDeep".
I'm wondering if I'm using react-query incorrectly. Should I be replacing the cached query data like this? Are there any better strategies for large datasets?
Screenshots
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: