Multiple query keys loading the same data [ANSWERED]
Suppose I have the following screens:
* All posts (
* User's posts (
* Post details (
When accessing the post details, I want the
At a first glance this does not look correct because it's violating DRY. But what is the proper way?
The solution that comes to mind is to pass the post as a prop to the post details and have that as the initial data, and meanwhile make a query to
* All posts (
GET /posts)* User's posts (
GET /users/{userId}/posts)* Post details (
GET /posts/{postId})When accessing the post details, I want the
initialData to check if this post was previously loaded by either the all posts query, or the user's posts query. I did this in the initial data by checking both separately using queryClient.getQueryData as such:At a first glance this does not look correct because it's violating DRY. But what is the proper way?
The solution that comes to mind is to pass the post as a prop to the post details and have that as the initial data, and meanwhile make a query to
posts/{id}, but I'm not 100% sure of this approach