T
TanStack2y ago
flat-fuchsia

invalidate query if useSearchParams() is update

how to invalidate query if searchParams (from useSearchParams()) in Next.js 14 got updated? I already tried with this code but it's causing infinity loop
No description
2 Replies
flat-fuchsia
flat-fuchsiaOP2y ago
oh but this is work fine maybe i should learn more about query key
quickest-silver
quickest-silver2y ago
Invalidating querykeys inside a useEffect is probably an antipattern. It's probably causing the useQuery to re-fetch the data, which is causing the page to re-render, which is firing the useEffect ♻️ Typically you invalidate queries in an onSuccess, onError or onSettled callback from a useMutation.

Did you find this page helpful?