Showing this error in next build: useSearchParams() should be wrapped in a suspense boundary at page
Answered
Muawiyah posted this in #help-forum
MuawiyahOP
Showing this error in next build: useSearchParams() should be wrapped in a suspense boundary at page,
I tried to wrap with <Suspense> tag too, but not working. I am using Next.js 15
Here's my
I tried to wrap with <Suspense> tag too, but not working. I am using Next.js 15
Here's my
/app/(root)/products/page.tsx code:import { fetchAllProducts } from "@/api/products";
import { ProductProvider } from "@/contexts/products";
import ProductsPageView from "@/page-sections/products/page-view";
import { cookies } from "next/headers";
import React from "react";
type searchParamsProps = Promise<{
q: string;
brand: string;
category: string;
}>;
const Products = async (props: { searchParams: searchParamsProps }) => {
const cookieStore = await cookies();
const token = cookieStore.get("token")?.value;
const { q, brand, category } = await props.searchParams;
const products = await fetchAllProducts(token as string, {
search: q,
brand: brand,
category: category,
});
return (
<ProductProvider value={{ products }}>
<ProductsPageView />
</ProductProvider>
);
};
export default Products;Answered by Muawiyah
Actually, I had that problem on search component, but it was showing
/products in error. So I wrapped the search component with the <Suspense> tag and it's worked6 Replies
MuawiyahOP
@/* @__PURE__ */ alfonsus Can you help me with the error? If you have time
@Muawiyah Showing this error in next build: useSearchParams() should be wrapped in a suspense boundary at page,
I tried to wrap with <Suspense> tag too, but not working. I am using Next.js 15
Here's my `/app/(root)/products/page.tsx` code:
import { fetchAllProducts } from "@/api/products";
import { ProductProvider } from "@/contexts/products";
import ProductsPageView from "@/page-sections/products/page-view";
import { cookies } from "next/headers";
import React from "react";
type searchParamsProps = Promise<{
q: string;
brand: string;
category: string;
}>;
const Products = async (props: { searchParams: searchParamsProps }) => {
const cookieStore = await cookies();
const token = cookieStore.get("token")?.value;
const { q, brand, category } = await props.searchParams;
const products = await fetchAllProducts(token as string, {
search: q,
brand: brand,
category: category,
});
return (
<ProductProvider value={{ products }}>
<ProductsPageView />
</ProductProvider>
);
};
export default Products;
can you add a
Like:
app/
page.tsx <--- this is your current page
loading.tsx <--- add this
loading.tsx to your path?Like:
app/
page.tsx <--- this is your current page
loading.tsx <--- add this
@B33fb0n3 can you add a loading.tsx to your path?
Like:
app/
page.tsx <--- this is your current page
loading.tsx <--- add this
MuawiyahOP
I have solved the issue, Anyway thank you for your reply
@Muawiyah I have solved the issue, Anyway thank you for your reply
please share your solution, so it helps others, that have the same issue
MuawiyahOP
Actually, I had that problem on search component, but it was showing
/products in error. So I wrapped the search component with the <Suspense> tag and it's workedAnswer
thanks for sharing!