Select option for QueryClient.getQueryData or allow useQuery select without queryFn #8452
-
I may be misunderstanding something here, but as far as I'm aware,
If my two assumptions are correct, this presents a bit of a problem for me: I'm migrating away from Redux, and my current architecture relied heavily on partial store subscriptions, something I don't want to lose. I also have a standardised api, so I wrap I'd also like to have reusable selectors, since I know the exact structure of the api response, which is the same for every response. But here is where I run into a problem: I cannot rely on
This is not a pattern I'd like to move away from, however there is a simple solution: allow To clarify further, the current paradigm for writing selectors is this:
I'd like to be able to do this:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Now that I think about it, |
Beta Was this translation helpful? Give feedback.
-
This is a typical client state management problem. You have some filters / params / whatever that you need to have available everywhere in your app. If you don’t want prop drilling, I’d suggest putting them somewhere into a global client state manager like redux or zustand. Then, your custom useQuery hook becomes:
I’m going into this in my talk “Thinking in React Query”: https://tkdodo.eu/blog/thinking-in-react-query |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late reply, I've been busy with another project that doesn't involve Tanstack stack. I suppose it's a matter of philosophy at this point. I don't see the issue with the implicit coupling, because the results are readily obvious in case a mistake happens. I generally prefer building up plug-and-play systems, where a component can automatically subscribe to a given "context"(in this case it would be the specific query), which in this paradigm is more difficult to achieve, albeit doable somewhat. |
Beta Was this translation helpful? Give feedback.
Sorry for the late reply, I've been busy with another project that doesn't involve Tanstack stack.
I suppose it's a matter of philosophy at this point. I don't see the issue with the implicit coupling, because the results are readily obvious in case a mistake happens. I generally prefer building up plug-and-play systems, where a component can automatically subscribe to a given "context"(in this case it would be the specific query), which in this paradigm is more difficult to achieve, albeit doable somewhat.