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

Inconsistent behaviour of currentData between useQuery and useLazyQuery #4494

Open
arvind0598 opened this issue Jul 3, 2024 · 0 comments
Open

Comments

@arvind0598
Copy link

Background:
I'm working on simple page that essentially gets a list of filters (including a date range) from the user, sends an API request to the backend to GET data, and render it in a table. All dates in the date range are columns in the table. To ensure I correctly move to a loading state, and always render the correct date range, I switched to currentData and isFetching instead of data and isLoading.

Issue:
My initial code was a useLazyQuery implementation. When I switched to currentData, it still returned the older data until the fetch was complete. After debugging for a bit, I switched to useQuery with a skip token, and it worked as expected.

Expected Behaviour:
Ideally, I think useLazyQuery should behave the same as useQuery and send currentData as undefined instead of the older data. While the example in the documentation uses a useQuery, there's nothing saying that useLazyQuery should be expected to behave differently. We could add it to the docs if this is expected behaviour.

Relevant Documentation:
From here.

While data is expected to be used in the majority of situations, currentData is also provided, which allows for a further level of granularity. For example, if you wanted to show data in the UI as translucent to represent a re-fetching state, you can use data in combination with isFetching to achieve this. However, if you also wish to only show data corresponding to the current arg, you can instead use currentData to achieve this.

Note: Using RTK ^2.2.6 and React ^18.3.3.

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

No branches or pull requests

1 participant