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

data property from useQuery having odd behaviour #3572

Open
kevinwolfcr opened this issue Oct 7, 2019 · 4 comments
Open

data property from useQuery having odd behaviour #3572

kevinwolfcr opened this issue Oct 7, 2019 · 4 comments

Comments

@kevinwolfcr
Copy link

Intended outcome:

It seems like the data property returned by the useQuery hook is having odd behaviour, take the following scenario:

  1. User lands in the app, which renders a list of rss feeds.
  2. When clicking on a rss feed, the app navigates to the feed page, which renders a loading skeleton while the feed entries are loaded.
  3. User navigates to another feed, which also renders a loading skeleton while the feed entries are loaded.
  4. User navigates back to the first feed, which renders a circular progress on top of the feed entries previously loaded.

Technical details

What I am doing is basically detect if query.loading === true and query.data === undefined in order to decide if I want to render the loading skeleton, if query.loading === true and query.data !== undefined, then I render the circular progress and if query.data !== undefined, then I render the list items.

Actual outcome (THE PROBLEM):

The main issue is that the query.data property is having odd behaviour, since it does not immediately relate to the query parameters I am sending, when I change from step 2 to step 3 of the above steps, then query.loading = true, but query.data remains in the same shape before the refetch, only updates when the date finishes fetching. Shouldn't it be undefined, just as in the first load?

How to reproduce the issue:

https://codesandbox.io/s/apollo-client-data-8y7p0
Video

(on the above gif you will note that on the initial load, data is undefined, while on subsequent ones, data remains the same, even if loading = true and the query parameters had changed)

Version

  • @apollo/react-hooks: 3.1.2
@kevinwolfcr
Copy link
Author

kevinwolfcr commented Oct 7, 2019

@kecoco16 discovered that if I useLazyQuery, then I get the intended behaviour: https://codesandbox.io/s/apollo-client-data-with-lazy-query-qq5uc

@Zoe7
Copy link

Zoe7 commented Oct 9, 2019

I'm also running into this issue. Looks to me like this is the same as people were reporting here: #2202

@Titozzz
Copy link

Titozzz commented Oct 22, 2019

This is effectively a duplicate of #2202, it's "funny" however that lazyQuery fixes it.

@harry-nguyen22
Copy link

@iamkevinwolf is right! Tested with useLazyQuery. Notice that if you are using polling then in new query you should call stopPolling first then call Query function. You will see the old data is empty!

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

4 participants