T
TanStack13mo ago
future-harlequin

Structuring query key and userId

Hello guys i have simple question, lets say u want to query user posts, should u then include userId into query key like this?
queryFn: fetchUserPosts, queryKey: ['posts', userId]
queryFn: fetchUserPosts, queryKey: ['posts', userId]
or would just posts as key be sufficient. Currently i'm not passing the user id as argument instead fetching current user inside fetchUserPosts, but i'm curious if this matters. Lets say for example u want to log out or log in as other user. Right now I would need to invalidate queries so that new user gets his posts. On the other hand if i would implement the approach of passing user id then i would need to update all mutations when im invalidating posts to pass userId that would get tedious quickly. Curious about your thoughts!
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?