To address the TypeScript issue you're encountering with params in Next.js 15, you need to adjust your code to handle the new asynchronous nature of params and searchParams. Here's how you can fix it:
- In your Server Component (page.tsx):
export default async function Page(props: { params: Promise<{ crewId: string }> }) {
const params = await props.params;
return <CrewPage crewId={params.crewId} />;
}
- In your Client Component (CrewPage.tsx):
'use client'
import { use } from 'react'
interface CrewPageProps {
crewId: string
}
export default function CrewPage({ crewId }: CrewPageProps) {
return <div>Crew ID: {crewId}</div>
}
This approach resolves the TypeScript issue by:
- Awaiting the
params promise in the Server Component (page.tsx).
- Passing only the necessary data (crewId) to the Client Component.
The key changes are:
- In the Server Component, we await the
params promise and extract the crewId.
- We pass only the
crewId to the Client Component, not the entire params object.
- The Client Component receives a plain
string prop instead of a Promise.
This solution aligns with the new asynchronous nature of params and searchParams in Next.js 15, as described in the Next.js 15 Upgrade Guide (https://nextjs.org/docs/app/building-your-application/upgrading/version-15#params--searchparams).
If you need to use the params directly in a Client Component, you can use React's use function as shown in the Next.js documentation (https://nextjs.org/docs/app/api-reference/file-conventions/page#examples):
'use client'
import { use } from 'react'
export function CrewPage({ params }: { params: Promise<{ crewId: string }> }) {
const { crewId } = use(params)
return <div>Crew ID: {crewId}</div>
}