QuizNot attempted
Updating search params
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 itssearchParamsprop (it is a Promise in Next 15)
- Copy the current params (
new URLSearchParams(useSearchParams())) so other filters survive,setthe one you need, thenrouter.push(orreplace) topathname?params - since Next 15 the page's
searchParamsprop is a Promise youawait. - 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
searchParamsaccess is the pre-15 API.