|
|
--- |
|
|
title: Entire page deopted into client-side rendering |
|
|
--- |
|
|
|
|
|
|
|
|
|
|
|
During static rendering, the entire page was deopted into client-side rendering by `useSearchParams` as there was no [Suspense boundary](/docs/app/api-reference/functions/use-search-params |
|
|
|
|
|
If a route is statically rendered, calling `useSearchParams()` will cause the tree up to the closest [Suspense boundary](/docs/app/api-reference/functions/use-search-params |
|
|
|
|
|
This allows a part of the page to be statically rendered while the dynamic part that uses `searchParams` can be client-side rendered. |
|
|
|
|
|
|
|
|
|
|
|
You can reduce the portion of the route that is client-side rendered by wrapping the component that uses useSearchParams in a Suspense boundary. |
|
|
|
|
|
For example if `app/dashboard/search-bar.tsx` uses `useSearchParams` wrap the component in a [Suspense boundary](/docs/app/api-reference/functions/use-search-params |
|
|
|
|
|
```tsx filename="app/dashboard/search-bar.tsx" |
|
|
'use client' |
|
|
|
|
|
import { useSearchParams } from 'next/navigation' |
|
|
|
|
|
export default function SearchBar() { |
|
|
const searchParams = useSearchParams() |
|
|
|
|
|
const search = searchParams.get('search') |
|
|
|
|
|
|
|
|
console.log(search) |
|
|
|
|
|
return <>Search: {search}</> |
|
|
} |
|
|
``` |
|
|
|
|
|
```tsx filename="app/dashboard/page.tsx" |
|
|
import { Suspense } from 'react' |
|
|
import SearchBar from './search-bar' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function SearchBarFallback() { |
|
|
return <>placeholder</> |
|
|
} |
|
|
|
|
|
export default function Page() { |
|
|
return ( |
|
|
<> |
|
|
<nav> |
|
|
<Suspense fallback={<SearchBarFallback />}> |
|
|
<SearchBar /> |
|
|
</Suspense> |
|
|
</nav> |
|
|
<h1>Dashboard</h1> |
|
|
</> |
|
|
) |
|
|
} |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- [`useSearchParams` static rendering documentation](/docs/app/api-reference/functions/use-search-params |
|
|
|