T
TanStack2y ago
eager-peach

React Query V5 infinite loop when using useEffect

Hi, I tried to migrate React query from V4 to V5 and I struggled to find a solution for this one. I removed the onSuccess callback for the useQuery methods and instead, use a classic useEffect const campaignReindex = useQuery({...}) useEffect(() => { if (campaignReindexed.data) { dispatch( notify({ type: 'success', message: campaignCode, description: t('notification:indexation:success:message'), duration: SNACKBAR_DISPLAY_DURATION, }), ) handleDialogClose() } }, [campaignReindexed.data]) When it is success status, I have a infinite loop because the dispatch is trigger all the time. Do you have an idea on how I can fix that please ? Is it possible to reset the capaignReindexed data to null or something like that ? The useEffect triggers all the time. Thank you very much !
1 Reply
plain-purple
plain-purple2y ago
data should be referentially stable so I wouldn't expect the effect to run more than once. can you show a simple codesandbox reproduction of the behaviour?

Did you find this page helpful?