How to handle dynamic variables in useQuery?
See original GitHub issueStarted fiddeling with this package and it looks really awsome. I am trying to understand how to automatically refetch when variables changes in a useQuery hook. I don’t know if i misunderstood something but this is what I have tried, and it only fetches once.`
On first render, it fetches correctly and logs correct data and variables. When setVariables it runs it updates those correctly, but no re-render is done and it logs new variables but same old data. Am i missing something here? There is no example for this.
function foo() {
const [variables, setVariables] = useState({});
const { data, loading } = useQuery(SOME_GRAPHQL_SCHEMA, {
variables,
suspend: false,
});
if(loading) return <p>Loading</p>;
console.log(data, variables);
return (...);
}
```
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:20 (1 by maintainers)
Top Results From Across the Web
The useQuery hook - with variables | Lift-off III - Apollo GraphQL
Use the useQuery hook to send the GET_SPACECAT query to the server. It takes a spaceCatId as a variable. Destructure the loading ,...
Read more >Make a GraphQL Query Dynamic with Variables and Urqls ...
The first thing we need to do is update our coursesQuery to accept a variable. We will declare an $offset: Int variable in...
Read more >react-query useQuery inside a provider with with dynamic ...
1 Answer 1 · I get that but what if I have a getTemplates call at the parent level. And I want all...
Read more >Getting the Most Out of Apollo's useQuery - Medium
So first you setup the query by passing query name and variables using useLazyQuery . It is different from useQuery because on top...
Read more >useQuery | TanStack Query Docs
useQuery · Optional · If set to true , queries that are set to continuously refetch with a refetchInterval will continue to refetch...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@rsjolundchas the first example should work. Please look at https://codesandbox.io/s/n4o02oz6jm - you should see different images for cats and dogs.
Hi,
Encountered this too. Issue of setting the value of
titledid not cause a re-query of the API.Here is the way I was able to resolve.
Before (not work):
Resolution (works!) - modified the query:
And then was able to achieve the desired outcome.