Skip to content

fix: show previous data while loading new one #121

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

Closed
wants to merge 1 commit into from

Conversation

FezVrasta
Copy link

This PR should fix the issue reported in #117

src/useQuery.ts Outdated
@@ -96,6 +96,8 @@ export function useQuery<
? 'cache-first'
: actualCachePolicy;

const lastResult = useRef();
Copy link
Author

Choose a reason for hiding this comment

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

we use this to be able to reference the actual previously returned data, we can't use observableQuery.getLastResult() because observableQuery may get invalidated and return null

@FezVrasta
Copy link
Author

I don't know why I'm getting the two type errors reported by CI, the code uses the same (smt || {}).data few lines above and it's perfectly happy with it.

@lukewlms
Copy link

lukewlms commented Apr 9, 2019

Thanks for submitting, this is broken compared to vanilla apollo React and needs a fix!

I suspect the original {}).data code works because it can never return null (so we never get to the right-hand side of the || and there's always .data). I.e. the "|| {}" is never called.

It also looks like you need to set a template on your useRef call so the compiler knows that you will be setting null OR the result type.

trojanowski added a commit that referenced this pull request Apr 18, 2019
…hat previous value of `data` is shown while loading new one and `networkStatus` should have a correct value in that case

BREAKING CHANGE: previous value of `data` is shown while loading new one

Closes #117
Closes #121
Closes #129
@FezVrasta
Copy link
Author

Closing in favour of #134

@FezVrasta FezVrasta closed this Apr 18, 2019
@FezVrasta FezVrasta deleted the fix-data-flush branch April 18, 2019 17:25
levindixon pushed a commit to levindixon/react-apollo-hooks that referenced this pull request Aug 22, 2019
…hat previous value of `data` is shown while loading new one and `networkStatus` should have a correct value in that case

BREAKING CHANGE: previous value of `data` is shown while loading new one

Closes trojanowski#117
Closes trojanowski#121
Closes trojanowski#129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants