Skip to content

useSearchParams not updating when using useNavigate #11424

Answered by kiliman
awilliams-qcells asked this question in Q&A
Discussion options

You must be logged in to vote

The 2-param version of URLSearchParams.has and .delete were introduced in Node.js v20.2.0, v18.18.0

https://nodejs.org/api/url.html#urlsearchparamshasname-value

As for browser compatibility

https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/has

If you can't upgrade, then here are replacement functions:

function hasSearchParam(params: URLSearchParams, name: string, value?: string) { 
  return typeof value === 'undefined' 
    ? params.has(name) 
    : params.getAll(name).includes(value)
}

function deleteSearchParam(params: URLSearchParams, name: string, value?: string) { 
  if (typeof value === 'undefined') {
    params.delete(name)
    return
  }
  const values = params.g…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@awilliams-qcells
Comment options

@kiliman
Comment options

Answer selected by awilliams-qcells
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants