Should external dependencies like a CRUD service be part of react query key? #8061
Unanswered
martynasd123
asked this question in
Q&A
Replies: 1 comment
-
I have prepared a minimal example. I found that this only happens with react query v3, but doesn't with @tanstack/react-query. The fetched value isn't updated, even though query is invalidated. It still calls the service, but not the new service instance with new "test" parameter. This isn't the case if service is added to the query key array |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I have this crud service interface:
I have different implementations of this service depending on whether I'm rendering the component in storybook, tests or production (production implementation uses axios to fetch data, while others just return some static data for testing)
My "fake" service looks like this:
And this is how I'm using it
The problem is that when I am wiring up the
MockStuffService
in storybook, I am re-creating it every render. I know I could modify it in-place, but that would be a bit more awkward. So for the fetchFn to get updated, I have to addstuffService
in the key list:This doesn't feel right. I know that under the hood react-query uses hashing to check if the function needs to be re-created, and stuffService might be large. Ideally I would want it to be compared by reference. Is there a better, more straightforward way to do this?
Beta Was this translation helpful? Give feedback.
All reactions