You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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
andisFetching
instead ofdata
andisLoading
.Issue:
My initial code was a
useLazyQuery
implementation. When I switched tocurrentData
, it still returned the older data until the fetch was complete. After debugging for a bit, I switched touseQuery
with a skip token, and it worked as expected.Expected Behaviour:
Ideally, I think
useLazyQuery
should behave the same asuseQuery
and send currentData as undefined instead of the older data. While the example in the documentation uses auseQuery
, there's nothing saying thatuseLazyQuery
should be expected to behave differently. We could add it to the docs if this is expected behaviour.Relevant Documentation:
From here.
Note: Using RTK ^2.2.6 and React ^18.3.3.
The text was updated successfully, but these errors were encountered: