Setquerydata
According tosetquerydata, query key was changed to be exact by default. Is there a way setquerydata not match a query key exactly when using setQueryData? Beta Was this translation helpful?
I'm testing out react-query for a project and am confused about the interaction between optimistic updates and select. And have another query, like the following, in another part of the application. It does not get triggered for re-render by setQueryData. I am only able to get the ability for 'select' to reduce re-renders when a refetch is called. Beta Was this translation helpful? Give feedback.
Setquerydata
.
Answer selected by YassienW, setquerydata. Answered by villesau Jan 28, From your comment, I would guess that you have tried immutable updates already, but it is setquerydata the most likely case of error.
.
The examples on this page are helpful, but only cover simplistic use cases. Currently, I'm using Immutable. I'm curious if TanStack has some built-in way that I missed. Beta Was this translation helpful? Give feedback.
Setquerydata
June 03, Alex Liu 5 min read. Let's say you're building an application that relies heavily on displaying and interacting with database information super rare situation as a dev, I know. You're also pretty good at React and Redux, so you start building your app with those libraries. Next, you make an API request for a dataset and put it in your Redux store. Then you render the Redux store data. Next comes manipulation of that data!
Tatuajes de lobo para mujer en la pierna
Anyways, sorry if it's not clear from the docs. Looking at the existing code, this would actually require modifying setQueryData , functionalUpdate , and probably others too, but having access to the full queryKey in the updater function would be very beneficial either as the second argument, or as a property of the second argument, so adding more items than queryKey wouldn't constitute a breaking change in the future. This is the source of my confusion, as it does seem to work similar to this, unless you add a select. Sign up for free to join this conversation on GitHub. But if you call setQueryData with the same reference, it does nothing. TkDodo Mar 24, Maintainer. Immutability is required when working in react. Note that if you only create a shallow new object, but then mutate firstName on data , it will still not work. You signed out in another tab or window. How to setQueryData without exact key The docs don't reveal anything about requiring immutable data. Just like setState from react itself would do nothing. You are right that setQueryData does indeed always inform subscribers when called, but I think this might change in v4.
I'm testing out react-query for a project and am confused about the interaction between optimistic updates and select.
Unfortunately, the updater function in setQueriesData doesn't currently have access to the exact query key. But since the updater function has no knowledge of the queryKey , it cannot know this. Most state managers in react need immutable updates to work correctly, which is why immer is so popular I guess :. Answered by villesau Return to top. You signed in with another tab or window. I'm not sure how that should work fuzzily, as it doesn't care about existing entries in the cache Beta Was this translation helpful? Note that if you only create a shallow new object, but then mutate firstName on data , it will still not work. Numbered list. You signed out in another tab or window. Notifications Fork 2.
You are absolutely right. In it something is also I think, what is it excellent idea.
What nice message