最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nextjs 15 - Include a client component as children of server component next.js 15 - Stack Overflow

programmeradmin3浏览0评论

I have a route in Next.js 15. It is a server component as I am fetching data from an api written in actions folder.

I have written a client component as I have to use a hook.

Below is the code:

app/marketplace/page.js

import { GetAllCourses } from "@/actions/api";
import MarketplaceComponent from "@/app/marketplace/marketplace_component";

export default async function Marketplace() {
  const { data } = await GetAllCourses();
  return (
    <>
      <MarketplaceComponent data={data} />
    </>
  )
} 

As you can see I am importing MarketplaceComponent which is a client component app/marketplace/marketplace_component.js

'use client';
import { useNetwork } from "@/components/hooks/web3/useNetwork";
import CourseList from "@/components/ui/course/CourseList";

const MarketplaceComponent = ({ data }) => {
  const { network } = useNetwork();
  return (
    <>
      {network.data}
      <CourseList courses={data} />
    </>
  )
}

export default MarketplaceComponent;

But I am getting the following error:

I believe we can include client component in a server component. Please can somebody explain the error and how can i fix it.

Thanks.

发布评论

评论列表(0)

  1. 暂无评论