Next.js Discord

Discord Forum

Showing this error in next build: useSearchParams() should be wrapped in a suspense boundary at page

Answered
Muawiyah posted this in #help-forum
Open in Discord
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;
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 worked
View full answer

6 Replies

@/* @__PURE__ */ alfonsus Can you help me with the error? If you have time
@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
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 worked
Answer
thanks for sharing!