Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

when loading, data is {} not undefined #3396

Closed
dnbkr opened this issue Aug 20, 2019 · 2 comments
Closed

when loading, data is {} not undefined #3396

dnbkr opened this issue Aug 20, 2019 · 2 comments

Comments

@dnbkr
Copy link

dnbkr commented Aug 20, 2019

Intended outcome:

when in a loading state, data is {} when it should be undefined:

const { data, loading } = useQuery(...)

if (loading === true) {
  console.log(!!data) // this is `true`
}

Actual outcome:

data is {}

this is particularly bad if you're using a truth-y check on data to see if the query has completed:

const { data } = useQuery(...)

if (data) {
   return <div>{data.user.name}</div>  // this will pass in typescript, but fail at runtime
}

How to reproduce the issue:

AFAIK run any useQuery hook

Version

3.0.0

@dylanwulf
Copy link
Contributor

#3388

@hwillson
Copy link
Member

hwillson commented Sep 6, 2019

React Apollo 3.1.0 is now available, and includes #3388. Thanks!

@hwillson hwillson closed this as completed Sep 6, 2019
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

3 participants