Open kevinwolfcr opened 5 years ago
@kecoco16 discovered that if I useLazyQuery
, then I get the intended behaviour: https://codesandbox.io/s/apollo-client-data-with-lazy-query-qq5uc
I'm also running into this issue. Looks to me like this is the same as people were reporting here: https://github.com/apollographql/react-apollo/issues/2202
This is effectively a duplicate of #2202, it's "funny" however that lazyQuery fixes it.
@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!
Intended outcome:
It seems like the
data
property returned by theuseQuery
hook is having odd behaviour, take the following scenario:Technical details
What I am doing is basically detect if
query.loading === true
andquery.data === undefined
in order to decide if I want to render the loading skeleton, ifquery.loading === true
andquery.data !== undefined
, then I render the circular progress and ifquery.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, thenquery.loading = true
, butquery.data
remains in the same shape before the refetch, only updates when the date finishes fetching. Shouldn't it beundefined
, just as in the first load?How to reproduce the issue:
https://codesandbox.io/s/apollo-client-data-8y7p0
(on the above gif you will note that on the initial load,
data
is undefined, while on subsequent ones,data
remains the same, even ifloading = true
and the query parameters had changed)Version
@apollo/react-hooks: 3.1.2