Skip to content

Infinitely Loading Query with useQuery and client #6038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bbrinx opened this issue Mar 9, 2020 · 2 comments
Closed

Infinitely Loading Query with useQuery and client #6038

bbrinx opened this issue Mar 9, 2020 · 2 comments

Comments

@bbrinx
Copy link

bbrinx commented Mar 9, 2020

It seems that when calling useQuery while passing through a client the query always returns loading true and reruns infinitely. This doesn't happen when using the client from the context. This error sounds very similar to apollographql/react-apollo#3270 and apollographql/react-apollo#3774 and a few more.

How to reproduce the issue:

const publicHttpSettings = 'http://localhost:3000/public_api'

httpLink = new HttpLink(publicHttpSettings);

const publicClient = new ApolloClient<any>({
  connectToDevTools: true,
  link: httpLink,
  cache: new InMemoryCache(),
});

const { loading, error, data } = useQuery(query, {
  variables: vars,
  skip: skip,
  displayName: displayName,
  client: publicClient,
});

console.log(data) // undefined
console.log(error) // undefined
console.log(loading) // true

Versions

"@apollo/client": "^3.0.0-beta.23",
"@apollo/link-batch-http": "^2.0.0-beta.3",
"@apollo/link-context": "^2.0.0-beta.3",
"@apollo/link-error": "^2.0.0-beta.3",
@dylanwulf
Copy link
Contributor

In your example, you're re-creating the client on every re-render, which is why you see infinite rerunning. Make sure that you're using the same client instance between re-renders.

@bbrinx
Copy link
Author

bbrinx commented Mar 11, 2020

@dylanwulf thanks! Totally missed that

@bbrinx bbrinx closed this as completed Mar 11, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants