transforming queries #522
Unanswered
jackmellis
asked this question in
General
Replies: 1 comment
-
can you confirm there are type issues when doing this? |
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
Uh oh!
There was an error while loading. Please reload this page.
-
So this is something I've come across a few times already. Say I've got a function that returns a query:
but I also have a selector, or similar, that wants to extract a property from that query. I want to use the same query under the hood, but just pluck something out of it.
I don't want to rewrite my
useQuery
line again, especially if it involves some complex fetching logic or something...that's okay but then in my component I'd need to do something like this:
Now I've got to grab both the original query, and the transformation. This is a simple example, but suppose my transformation is more complicated or relies on other bits and pieces. It'd be good if I could have something like
so although the actual react-query call is fetching the basket, I can return a subset of that data but still have the original query properties.
Right now to achieve that I'd have to do something like this:
I also fear this could cause other complications, like type mismatches on the useQuery options.
I was thinking you could maybe have some sort of transform option that runs after your query has fetched and cached. Imagine something like this:
Apologies for the probably over-simplified use case!
Beta Was this translation helpful? Give feedback.
All reactions