Next.js · Middle · Question 64 of 75
How can a deeply nested server component read the [lang] segment of the root layout without prop drilling?
import { lang } from 'next/root-params'
const current = await lang()- ✓Correct answer: Import the generated getter from
next/root-params - 2Call
useParams()in the server component - 3Store it in a global variable in the root layout
Explanation
Root params are dynamic segments above the root layout. The getters work in server components but not in client components, Server Actions or Route Handlers.