Skip to content
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

useApolloNetworkStatus() doesn't react on query? #36

Closed
github0013 opened this issue Nov 20, 2020 · 1 comment
Closed

useApolloNetworkStatus() doesn't react on query? #36

github0013 opened this issue Nov 20, 2020 · 1 comment

Comments

@github0013
Copy link

function GlobalLoadingIndicator() {
  const status = useApolloNetworkStatus()
  console.log("status.numPendingQueries", status.numPendingQueries)
  if (status.numPendingQueries > 0) {
    return <p>Loading …</p>
  } else {
    return null
  }
}

const App = () => {
  const { loading, error, data } = useQuery(Query)
  console.log("loading", loading)
  console.log("data", data)

  return <></>
}

expected

  • status.numPendingQueries 0
  • loading true
  • data undefined
  • status.numPendingQueries 1
  • loading false
  • data {GenreCollection: Array(19)}
  • status.numPendingQueries 0

Order might be different, but I at least was expecting status.numPendingQueries would become 1, but it never happens.

actual

react-apollo-network-status_-_CodeSandbox

codesandbox

https://codesandbox.io/s/typescript-react-material-ui-5zxqh

I copied the sample code from readme, and added App to it. How is my code not running properly?

@amannn
Copy link
Member

amannn commented Nov 20, 2020

Thanks for the report!

Yes, this is a known limitation at this point. I think this is a duplicate of #19.

The topic is a bit tough because Apollo fetches data during render which is before the subscription is set up (useEffect). I've wrote about some potential solutions here: #19 (comment).

Thank you for the reproduction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants