Skip to content
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

Provide a previousData property in useQuery/useLazyQuery results #7082

Merged
merged 6 commits into from
Sep 28, 2020

Conversation

hwillson
Copy link
Member

Alongside their returned data property, useQuery and useLazyQuery now also return a previousData property. Before a new data value is set, its current value is stored in previousData. This allows more fine-grained control over component loading states, where developers might want to leverage previous data until new data has fully loaded.

@benjamn just a heads up that I did look into moving the previousData handling up the chain into the AC core itself. The amount of work needed to get this functionality in place would have been more substantial however (as the lastResult tracking we’re doing in ObservableQuery doesn’t quite line up with what we’re looking for here), so I’ve left it in the React layer for now (where we were already tracking previousData, but just not exposing it). This should address most of the oustanding issues around this functionality, and we can always consider this a stepping stone. Changing how this works internally in the future will be hidden from useQuery / useLazyQuery consumers. Thanks!

Fixes #6603

Alongside their returned `data` property, `useQuery` and
`useLazyQuery` now also return a `previousData` property. Before a
new `data` value is set, its current value is stored in
`previousData`. This allows more fine-grained control over
component loading states, where developers might want to leverage
previous data until new data has fully loaded.

Fixes #6603

Verified

This commit was signed with the committer’s verified signature.
benjamn Ben Newman

Verified

This commit was signed with the committer’s verified signature.
benjamn Ben Newman

Verified

This commit was signed with the committer’s verified signature.
benjamn Ben Newman

Verified

This commit was signed with the committer’s verified signature.
benjamn Ben Newman
@benjamn benjamn added this to the Post 3.0 milestone Sep 28, 2020

Verified

This commit was signed with the committer’s verified signature.
benjamn Ben Newman
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hwillson Thanks for this!

I made a few tweaks, but the main thing was to let result.previousData persist across multiple results. See the test I added for an example where result.data can be undefined twice in a row.

@hwillson
Copy link
Member Author

Great catch @benjamn - thanks for finishing this up!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants