React-apollo: when loading, data is {} not undefined

Created on 20 Aug 2019  ·  2Comments  ·  Source: apollographql/react-apollo

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

Most helpful comment

3388

All 2 comments

3388

React Apollo 3.1.0 is now available, and includes https://github.com/apollographql/react-apollo/pull/3388. Thanks!

Was this page helpful?
0 / 5 - 0 ratings