Proposing an abstraction for conditional queries #6540
Unanswered
costelinivictor
asked this question in
Ideas
Replies: 1 comment
-
in my experience, when someone wants a "fetch on click", they want lazy queries, where the value that is passed to |
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.
-
The issue
We can already perform conditional queries by manipulating the
enabled
property, but I was wondering if we could create an abstraction for that.In a scenario where a button triggers a fetch, for example, we'd do something like this:
We introduce an
useEffect
and anuseState
, creating a lot of boilerplate code to achieve the desired behavior.The proposed solution
My suggestion is for us to modify
useQuery
so it:fetch
that can be called by the component, removing the need foruseEffect
anduseState
hooksfetchOnMount
, with its default value astrue
Why not just use a Mutation?
useQuery
already has all the cache handling and we're all used to useuseQuery
for fetching data.Remarks
As expected for a GitHub Discussion, this is just an idea and, even if this goes forward, it's not even close to a final version.
I'd love your input for the following questions:
useConditionalQuery
?Beta Was this translation helpful? Give feedback.
All reactions