Next.js · Junior · Question 34 of 75
How do you get the ?page=2 query parameter in a server page?
- ✓Correct answer: From the
searchParamsprop:const { page } = await searchParams - 2Via
useSearchParams()directly in the server page - 3Via
params.page- the query goes intoparams
Explanation
The page receives searchParams as a promise. Reading the query makes the page dynamic, because the values are known only at request time. In client components, use useSearchParams(). params contains only the dynamic path segments.