Created
April 29, 2021 14:42
-
-
Save yilmazcakmakci/0bbf03305c886c4e4503e7e1c9aef271 to your computer and use it in GitHub Desktop.
Get query of the current location with key-value pairs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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