Skip to content

Instantly share code, notes, and snippets.

@yilmazcakmakci
Created April 29, 2021 14:42
Show Gist options
  • Select an option

  • Save yilmazcakmakci/0bbf03305c886c4e4503e7e1c9aef271 to your computer and use it in GitHub Desktop.

Select an option

Save yilmazcakmakci/0bbf03305c886c4e4503e7e1c9aef271 to your computer and use it in GitHub Desktop.
Get query of the current location with key-value pairs
const useQuery = () => {
const url = new URL(window.location.href)
const params = new URLSearchParams(url.search)
const query = {}
for(const pair of params.entries()) {
query[pair[0]] = pair[1]
}
return query
}
console.log(useQuery())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment