docs: fix JS/TS code block (#60854)

And also making it more clear it doesn't have to be two separate files.
This commit is contained in:
Lee Robinson 2024-01-18 17:48:24 -06:00 committed by GitHub
parent fcfa45cd8e
commit 1cafe945ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,28 +10,25 @@ Reading search parameters through `useSearchParams()` without a Suspense boundar
Ensure that calls to `useSearchParams()` are wrapped in a Suspense boundary. Ensure that calls to `useSearchParams()` are wrapped in a Suspense boundary.
```tsx title="app/page.tsx" ```jsx title="app/search.js"
import { SearchBar } from './search'
import { Suspense } from 'react'
export default function Page() {
return (
<Suspense fallback={<div>Loading...</div>}>
<SearchBar />
</Suspense>
)
}
```
```jsx title="app/search.tsx"
'use client' 'use client'
import { useSearchParams } from 'next/navigation' import { useSearchParams } from 'next/navigation'
import { Suspense } from 'react'
export function Search() { function Search() {
const searchParams = useSearchParams() const searchParams = useSearchParams()
return '...' return <input placeholder="Search..." />
}
export function Searchbar() {
return (
// You could have a loading skeleton as the `fallback` too
<Suspense>
<Search />
</Suspense>
)
} }
``` ```