Reusing data returned from a List query in a Single query #2946
Unanswered
DannyBiezen
asked this question in
Q&A
Replies: 1 comment
-
Every query is independent and has totally separate cache entries. In other words, there's no "normalization" of results to deduplicate values across separate queries. This is an intentional part of RTKQ's design: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have defined two endpoints to retrieve data using RTK-Query in React-Native:
/users
and/users/{id}
. I have two react-hooks for thisThese endpoints return the list of all the users and an individual user.
The initial screen opened by the user will call
/users
As expected the users will be loaded into the store. If I then navigate to a user's profile screen I want to be able to reuse the data from the
/users
endpoint without making a new request to my API.I can achieve this by reusing the hook for
/users
and filtering the data to get that specific user:This works fine - however the user could go to this screen without having previously loaded the
/users
data. In this case we would retrieve all users instead of a single user which is not performant.Is it possible to make sure a request is not made when a specific user has already been loaded into the list?
Beta Was this translation helpful? Give feedback.
All reactions