The useSearchParams Hook for URL Queries
The useSearchParams hook gives your client component read-only access to the URL's query string. Use it to build UIs that react to URL changes, like filtering a list or displaying search results.
Why it exists
Web apps often store state in the URL's query string, like ?page=2&sort=asc. Manually parsing this from the browser's location object is clumsy and not reactive. The useSearchParams hook provides a clean, Next.js-native way to read these values inside your components and automatically re-render when they change.
The mental model
Think of useSearchParams as a read-only subscription to the URL's query string. It gives you an object that represents the current parameters. When the URL changes, Next.js gives you a new version of this object, triggering a re-render in your component with the updated data. You don't read the URL; you subscribe to its state.
How it works
First, mark your component with 'use client' at the top of the file. Then, import the hook from next/navigation. Calling const searchParams = useSearchParams() inside your component gives you a read-only URLSearchParams object. You can then use its methods, like searchParams.get('sort') to retrieve a value, or searchParams.has('page') to check if a parameter exists. Any change to the URL's query string will cause your component to re-render.
When to use it
Use this hook whenever a Client Component's rendering logic depends on URL query parameters. This is common for building search result pages that reflect the search term, filtering and sorting controls for a list of items, or handling pagination where the page number is stored in the URL.
When not to use it
The most common mistake is using this hook in a Next.js Server Component. It is a client-side hook and will cause an error. To access search parameters in a Server Component (like a page.js file), use the searchParams prop that is automatically passed to the page. Also, do not use this hook if you need to modify the URL; for that, you need to use the useRouter hook or the <Link> component to navigate to a new URL with updated parameters.
One canonical example
Here is a simple component that displays a search query from the URL. If the URL is /search?q=react, it will display "Searching for: react".
'use client'
import { useSearchParams } from 'next/navigation'export default function SearchLabel() {
const searchParams = useSearchParams()
const query = searchParams.get('q')return Searching for: {query}
}Interview question
Which scenario represents the most common misuse of the useSearchParams hook?
- a.Forgetting to import it from 'next/navigation'.
- b.Attempting to change the URL's query parameters directly.
- c.Accessing a query parameter that does not exist in the URL.
- d.Using it within a Next.js Server Component.Correct
Why? this is the answer
The card explicitly states that using this hook in a Next.js Server Component is 'The most common mistake' because it is a client-side hook. While attempting to modify the URL (B) is also incorrect usage, the card highlights the Server Component misuse as the most frequent error.
Just read this? Test yourself on what you have been reading.
Read the original → nextjs.org
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on react — each one lists the topics its interview covers.
See open roles