How can I grab searchParams from a server component?
Answered
Champagne D’Argent posted this in #help-forum
Champagne D’ArgentOP
example: www.thisismyurl.com/blog/drama?view=movies
I can grab drama from the params, but can't figure out the search params to get movies
I can grab drama from the params, but can't figure out the search params to get movies
export default async function Genres({ params: { slug } : Params) {
// slug = drama (working)
// query.view = movies (not sure)
}Answered by Nelson
You can get them from the props.
https://nextjs.org/docs/app/api-reference/file-conventions/page
export default function Page({
params,
searchParams,
}: {
params: { slug: string }
searchParams: { [key: string]: string | string[] | undefined }
}) {
return <h1>My Page</h1>
}https://nextjs.org/docs/app/api-reference/file-conventions/page
2 Replies
You can get them from the props.
https://nextjs.org/docs/app/api-reference/file-conventions/page
export default function Page({
params,
searchParams,
}: {
params: { slug: string }
searchParams: { [key: string]: string | string[] | undefined }
}) {
return <h1>My Page</h1>
}https://nextjs.org/docs/app/api-reference/file-conventions/page
Answer
Champagne D’ArgentOP
@Nelson that worked perfectly, thank you so much!