Strange behaviour with react query #3990
Unanswered
eason123deng
asked this question in
Q&A
Replies: 1 comment
-
very hard to say with this abstract code. a codesandbox reproduction would be best. please make sure to include all dependencies of the query (everything that is used inside the queryFn) in the queryKey! |
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
Uh oh!
There was an error while loading. Please reload this page.
-
I am currently working on a project with a lot of class components. Recently my team has decided to start using react query in some of the class components and I encountered a very strange bug in which useQuery is making an API call with an incorrect payload/query param (the request URL has an extra slash / in the middle and one of the query param is missing) for a particular usage of react query.
To integrate useQuery with class components, I adopted an HOC approach as follow:
The above setup works nicely until I wrapped ParentComponent with useFetchImage, the modified ParentComponent.tsx becomes something like:
With the above modification, withFetchImage works as expected as long as ComponentA never unmounts (ComponentA is the only component that will use useQuery). As soon as ComponentA remounts, react query starts calling the same API with corrupted URL and payload. I was able to fix the issue by removing useFetchImage from either ParentComponent or ComponentA, but I have absolutely no clue why it occurs. Does anyone know why this weird issue occurs?
Beta Was this translation helpful? Give feedback.
All reactions