I am experimenting with Next.js 13 app directory and React 18's Server Components.
Following the documentation I put an async fetch()
call inside a Server Component and I mark the component as async.
But then when I place it as a child of a Client Component, it fails with error
Objects are not valid as a React child (found: [object Promise])
If I place it as a child of another Server Component, it works as intended.
Why?
Code here:
### page.tsx
import { ClientComp } from './ClientComp'
export default function Page() {
return <ClientComp />
}
### ClientComp.tsx
"use client";
import { ServerComp } from "./ServerComp";
export function ClientComp() {
{/* @ts-expect-error Async Server Component */}
return <ServerComp />
}
### ServerComp.tsx
export async function ServerComp() {
return <h2>ServerComp</h2>
}