-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useQuery
resets data
to undefined after updating variables
#6866
Comments
Yes, this is an intentional change. See #6566 |
Got it. Thanks, @dylanwulf ! |
I'm also affected by this breaking change and this is major unwanted change. As it was previously mentioned, in UI you usually want to keep previous state until new data is loaded instead of having intermediate empty state that shows blank page and global spinner. |
I'm happy to share that we finally have an implementation of |
Hi
Prior to v3, when I use
useQuery
(i.e. from@apollo/react-hooks
v3.1.5), thedata
is set toundefined
while loading the first query (and that makes sense), but whenever I update the query, like updating its variables, thedata
remains unchanged whileloading
until it sets to the new value when the query finishes.However, after updating to
@apollo/client
v3 (or@apollo/react-hooks
v4), thedata
resets toundefined
whenever the query reloads.That became a problem because I'd like to not rely on "Initial Loading" states for the data after an initial value is already present. I'd like to remain using the data until it updates.
I didn't see any mention of this change in the migration guide, so I'm not sure if this is a bug or an intentional change...
Intended outcome:
Considering the folowing code:
I expected that, whenever I update
var
, thedata
result remained the same value as the previous query, until it changes to the new value whenloading
finishes.Actual outcome:
Since
v3
, when I changevar
, thedata
result resets toundefined
whileloading
istrue
, then updates to the new value whenloading
finishes.How to reproduce the issue:
Here's a sandbox using
@apollo/react-hooks
v3.1.5https://codesandbox.io/s/zen-bose-sgymg?file=/src/App.js:319-401
And here's the same code using
@apollo/client
v3.1.3https://codesandbox.io/s/falling-fog-45kfd?file=/src/App.js
Notice that in the previous version, the
data
value never returned toundefined
after the first query. While in the new version, it returns toundefined
, making it always behave like a "First query" in the app.Note how this can cause different loading behaviour in the app:
How it was
How it is now
Is this really a bug or is it an intentional change? If it is intentional, how could I keep the previous data value without relying on an additional state?
Thanks!
The text was updated successfully, but these errors were encountered: