URL state with searchParams in Next.js
📖 Scenario: You are building a simple product filter page in Next.js. The page should read a category from the URL's search parameters and show it on the page. This helps users share filtered views by URL.
🎯 Goal: Create a Next.js functional component that reads the category search parameter from the URL and displays it. The component should update if the URL changes.
📋 What You'll Learn
Use Next.js App Router with a functional component
Use the
useSearchParams hook to read URL search parametersDisplay the current
category parameter value on the pageUpdate the displayed category if the URL changes
💡 Why This Matters
🌍 Real World
Many web apps use URL search parameters to keep track of filters or settings so users can share links with the current view.
💼 Career
Understanding how to sync UI state with URL parameters is important for building user-friendly, shareable web applications in Next.js.
Progress0 / 4 steps