-
Notifications
You must be signed in to change notification settings - Fork 786
Query result proposal: use actual data or {} to enable easier destructuring #1686
Comments
I think this was resolved in #1635 issue report 👍 |
I think with version 2.1.0-beta.3 you need to change the typings from |
I'm using 2.1.8 and typings say Line 97 in 3985b47
However, in runtime |
At one point, there was an empty object. It is now TData | undefined. Related #1917 |
@rosskevin I think it's the other way round. |
Related #1917 |
@alamothe at one point it was returning As mentioned in #2423 (comment), the biggest problem with using For example (as that was the case some time ago), I needed all of the below to determine if I needed to render the <Query {...rest}>
{result => {
if (result.error) {
// error handling code
} else if (result.loading || Object.keys(result.data).length < 1) {
// could be an empty object at this point because {}
return LoadingComponent ? <LoadingComponent /> : null
} else if (result.data) {
// The above code guarantees that at this point it should be our real data
const data: TData = result.data as TData
return children({ client: result.client, data })
} else {
throw new Error('Unexpected fall through, check the log.')
}
}}
</Query> While this is easier for destructuring, as shown above, it requires more logic to determine if you have actual data to render. |
I absolutely agree with your rationale, and prefer But as far as I remember, it was If it's reverted to |
React Apollo has been refactored to use React Hooks behind the scenes for everything, which means a lot has changed since this issue was opened (and a lot of outstanding issues have been resolved). We'll close this issue off, but please let us know if you're still encountering this problem using React Apollo >= 3.1.0. Thanks! |
Guys, I'm receiving the error above when I update above
My code
|
In the Query Component, if the query is still loading, the data variable will be
undefined
. This behavior is due to the following line:What do you think of making data
{}
instead ofundefined
? This way, it will be possible to do destructuring ofdata
like so:Currently, this will throw
Uncaught TypeError: Cannot read property 'heroes' of undefined
. With the old query HOC pattern, this was not an issue (from the docs):Since
loading
was moved out of data in the new query component, I can also see why it might make more sense to keepdata
asundefined
whenloading
is true. Just wanted to get some opinions. 🎉Version
react-apollo@2.1.0-beta.2
The text was updated successfully, but these errors were encountered: