NextJS, get additional attributes in client component #208981
Replies: 2 comments 2 replies
|
In the App Router you can't hand a promise to a client component - props crossing the server/client boundary have to be serializable. Since Next 15, // Server Component
export default async function Page({ searchParams }) {
const params = await searchParams; // resolve the promise here
const details = { id: params.id, name: params.name, ...params }; // plain object
return <ClientComponent details={details} />;
}
// Client Component
'use client';
export function ClientComponent({ details }) {
return <div>{details.id} - {details.name}</div>;
}The reason you see |
|
Are you trying to pass data from your server component to the client one? If so, you might need to serialize and pass those attributes through props or URL params instead of relying on the promise alone. Can you share a quick code snippet of how you're currently passing the data? That'll help figure out why the other stuff isn't making it through. |
Uh oh!
There was an error while loading. Please reload this page.
🏷️ Discussion Type
Question
Body
Hi,
I need to get additional attributes in a client component from a server component. The server component returns details via search parameters as a promise, so async, await ... I can get the id on the client component, but not the other attributes.
Guidelines
All reactions