useQuery with the same key but different options
Hi!
In my app, there's a profile page for each user.
In this page, you can see each of the user's friends avatars in a tiny circle.
When you click these circles, there's a popup that shows their information.
I currently use the same queryKey for both queries (the main one for the actual profile page, and for each one of its friends). Everything works well and I love the fact that they share results.
I'm trying to make the friends query stop refetching when it mounts. The problem though, is that its query options object seems to be ignored due to the settings of the main profile query.
Is there a way to work around this?
6 Replies
optimistic-goldOP•4y ago
* The friends query remounts because it is paginated.
optimistic-goldOP•4y ago
Here's a super-minimal sandbox to demonstrate the question: https://codesandbox.io/s/tanstack-query-same-key-different-options-p8j8yb
Click next and previous, you'll see in console that a fetch is made every time, and it ignores the
refetchOnMount: false that is set.itayganor
CodeSandbox
tanstack-query__same-key-different-options - CodeSandbox
tanstack-query__same-key-different-options by itayganor using @tanstack/react-query, @tanstack/react-query-devtools, @tippyjs/react, axios, react, react-dom, styled-components
optimistic-goldOP•4y ago
I just moved this question to Github Discussions for future readers: https://github.com/TanStack/query/discussions/4262
GitHub
useQuery with the same key but different options · Discussion #4262...
Hi! In my app, there's a profile page for each user. On this page, you can see each of the user's friends' avatars in a tiny circle. When you click these circles, there&...
conscious-sapphire•4y ago
It doesn't refetch because of a mount, it refetches because of a query key change. To avoid refetches, set a higher staleTime
optimistic-goldOP•4y ago
The issue turned out to be a bug in my code that hasn't made it into the reproduction example.
Sorry for that!
Would you mind deleting the GitHub discussion I opened?
conscious-sapphire•4y ago
done