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
flat-fuchsiaOP•2y ago
oh but this is work fine
maybe i should learn more about query key
quickest-silver•2y 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.