Skip to content

QuizNot attempted

Updating search params

In a Client Component, how do you set ?category=shoes without losing other params, and how does the page read it in Next 15+?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • const params = new URLSearchParams(useSearchParams()); params.set('category', 'shoes'); router.push(${usePathname()}?${params}); the page awaits its searchParams prop (it is a Promise in Next 15)
  • Copy the current params (new URLSearchParams(useSearchParams())) so other filters survive, set the one you need, then router.push (or replace) to pathname?params
  • since Next 15 the page's searchParams prop is a Promise you await.
  • Not window.location.search: triggers a full page reload.
  • Not Context: the server page can't read Context and the URL isn't updated.
  • Not router.push('?category=shoes') + sync read: it drops other params, and synchronous searchParams access is the pre-15 API.