useQuery making two calls #7712
Replies: 3 comments 7 replies
-
I read this about why react-query will run twice on initial load under certain circumstances, maybe it's related. |
Beta Was this translation helpful? Give feedback.
-
it's because |
Beta Was this translation helpful? Give feedback.
-
@TkDodo thanks for your work on this fantastic library. I have a related, but slightly different case: the query errors on first load (imagine apis 500-ing when app starts). I have Stackblitz for minimal reproduction Expectation: parent invokes Actual: I believe the child re-using the query calls retries Appreciate that Is there a recommended approach to avoid a potential ddos in this case? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a Parent component where I am defining my query, and
queryFn
. OnceisLoading
is false and there is no error the child is executed. In the child I useuseQuery
again to get that data. By doing this I can access that data anywhere in the app without having to prop drill. I have successfully used this method multiple times, however, in this one component it is making a call twice instead of just once. Any thoughts on why?Parent component
Child component
const { data } = useQuery<ProductPublicDto | undefined>({ queryKey: ["getProductData"] })
The data hasn't changed, and it only happens on the initial load, I just don't know why. In the past I have used
getQueryData
but we are moving away from using that because React 19 has re-rendering issues with it.Beta Was this translation helpful? Give feedback.
All reactions