T
TanStack•3y ago
jolly-crimson

Refetch is not happening (dependent query)

Hello ! I setup a dependent query in way to refetch as my value change. I would like to update my "applications" when my "environnementId" change, not only on the first render. The code on the screenshot doesn't work because my "environnementId" is never false again after picking a value. Do you have some clues ?
No description
7 Replies
jolly-crimson
jolly-crimsonOP•3y ago
environnementId is a simple state :
No description
jolly-crimson
jolly-crimsonOP•3y ago
My change function here :
No description
jolly-crimson
jolly-crimsonOP•3y ago
Finally the query hook (I use parseInt beacause my endpoint need a number):
No description
jolly-crimson
jolly-crimsonOP•3y ago
And this is the jsx for my select elements (I use react-hook-form):
No description
yammering-amber
yammering-amber•3y ago
Hi. You have to put environmentId in the queryKey so that you get a new query whenever env changes.
yammering-amber
yammering-amber•3y ago
Practical React Query
Let me share with you the experiences I have made lately with React Query. Fetching data in React has never been this delightful...
jolly-crimson
jolly-crimsonOP•3y ago
Yeah ! I totaly forget this, thanks you 😄

Did you find this page helpful?