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

useQuery fails to return cached data when variables are changed #3742

Open
zicodeng opened this issue Dec 8, 2019 · 0 comments
Open

useQuery fails to return cached data when variables are changed #3742

zicodeng opened this issue Dec 8, 2019 · 0 comments

Comments

@zicodeng
Copy link

zicodeng commented Dec 8, 2019

Consider the following queries

useQuery(POSTS, {
  variables: {
    offset: currPage * 20
  }
})

where currPage is a React local state variable. It will get updated when user paginates

Intended outcome:

When currPage=1, new data is fetched, when currPage=2, new data is fetched... When user paginates to the previous page (page 1), because query with currPage=1 is already fetched, it should just read the cache

Actual outcome:

When user paginates from page 1 to page 2, new data for page 2 is fetched, however, when user paginates back to page 1, cache is not read, data is still displayed for page 2

How to reproduce the issue:

Versions

@apollo/client: ^3.0.0-beta.14
react-apollo: ^3.1.3

Issue is also reported in Apollo client GitHub: apollographql/apollo-client#5659

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

1 participant