T
TanStack17mo ago
apparent-cyan

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
apparent-cyan
apparent-cyanOP17mo ago
oh but this is work fine maybe i should learn more about query key
dependent-tan
dependent-tan17mo 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?