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 ?

7 Replies
jolly-crimsonOP•3y ago
environnementId is a simple state :
jolly-crimsonOP•3y ago
My change function here :

jolly-crimsonOP•3y ago
Finally the query hook (I use parseInt beacause my endpoint need a number):
jolly-crimsonOP•3y ago
And this is the jsx for my select elements (I use react-hook-form):

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•3y ago
You could have a look here for explanation: https://tkdodo.eu/blog/practical-react-query#treat-the-query-key-like-a-dependency-array
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-crimsonOP•3y ago
Yeah !
I totaly forget this, thanks you 😄