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
2 Replies
apparent-cyanOP•17mo ago
oh but this is work fine
maybe i should learn more about query key
dependent-tan•17mo 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.