-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: add structural sharing of data between query results #883
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
feat: add structural sharing of data between query results #883
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/dr5amp18u |
Ooooooooo... This is awesome. What else can you tell me about this? |
This will make sure that if some query is returning a list of todos, and at some point a todo in this list changes, the references to the other todos will remain the same. This allows users to easily check if some part of the data has changed or not (which can be used to prevent unnecessary renders or effects from triggering). Together with a
|
2a23b3c
to
2bc0c81
Compare
Well shoot dang, that sounds like something I've needed for a while but never tried to build yet. |
Do you feel this is ready to merge? |
It passes all tests and did some integration testing so this one should be ready to go 👍 PS: do you also have some time to take a look at the other PRs? |
Yeah, ping me on what your priority is and I'll get to it. |
🎉 This PR is included in version 2.6.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Is this feature documented somehow in the documentation? |
Well, it's not really a feature you "use", but more of an optimization that is just "there" by default. Maybe we could add a section to the docs that talks about what it is to help people know that it's something they normally will want to keep on. Structural sharing just ensures that if serialized responses don't change over time that their identities are deeply persisted, or in other words, its to make your application code better understand that the |
Ah, right, yeah. As a developer I would definitely appreciate having a short explanation of this and other features. What it means, a code example where it obviously helps me, and how it "breaks" if I turn it off / why I would potentially want to turn it off. |
Is there any documentation or example of how someone would implement a useQuerySelector or similar hook? I have a list of tasks in my app and I often want to limit my re-renders to only the tasks that actually updated in the list after injecting updated tasks via a socket. Seems like this would be a good fit for useQuerySelector or similar. I'm thinking this would allow me to pass in a function that defines what data I want from a specific call of a query and if that data hasn't changed the hook wouldn't trigger a re-render, is that correct? |
No description provided.