Quantcast
Channel: Active questions tagged navigation - Stack Overflow
Viewing all articles
Browse latest Browse all 9839

Nextjs 13: How to show the loading ui when search params changes?

$
0
0

I have this component here:

const MyComponent = (props: Props) => {  const router = useRouter();  const searchParams = new URLSearchParams(    Array.from(useSearchParams().entries())  );  const form = useForm({    defaultValues: {      category: searchParams.get("category") || NaN,      subcategory: searchParams.get("subcategory") || NaN,    },  });  const subcategory = form.watch("subcategory");  const updateParams = (    category: string | number,    subcategory: string | number  ) => {    searchParams.set("category", String(category));    searchParams.set("subcategory", String(subcategory));    router.push(`/my-url/?${searchParams.toString()}`);  };  useEffect(() => {    if (subcategory) {      updateParams(category, subcategory);    }  }, [subcategory]);  const category = form.watch("category"); 

That updates the search params based on user input (from checkout buttons). This triggers page refetch to update the data from UI. But, for some reason, it doesn't trigger the loading.tsx from this route.

I saw people reporting the same error at this github issue. Is there any workaround to make searchparams trigger a loading screen?

I know it would work with path param, but I need a URL with search parameters.


Viewing all articles
Browse latest Browse all 9839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>