Next.js Discord

Discord Forum

useSearchParams and static rendering

Palomino posted this in #help-forum
Open in Discord
If I'm understanding the docs correctly, it suggest that using useSearchParams (in a static route) will cause its client component and its children to not be sent with the initial HTML and only be rendered on the client.

Which brings up the question of whether I should use searchParams or useSearchParams. Using searchParams will make the whole route dynamic while using useSearchParams will make the component a client component.

It seems to me that useSearchParams is better since it can instantly serve up prerendered html at the cost of sending more JS code to the client whereas with searchParams, you will have to render the route on every request.

The only case I can think of where I would want to use searchParams is when the route needs to be dynamic because of other reasons (fetching non-cached data) but otherwise, I would use useSearchParams.

As a more general question, if I could choose to make a component a client component or opt the whole route into dynamic rendering, which is the better option?

0 Replies