You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
609 B
24 lines
609 B
export function useSearchParams() { |
|
const searchParams = new URLSearchParams(window.location.search) |
|
|
|
return { |
|
searchParams, |
|
get: (key: string) => searchParams.get(key), |
|
set: (key: string, value: string) => { |
|
searchParams.set(key, value) |
|
window.history.replaceState( |
|
null, |
|
'', |
|
`${window.location.pathname}?${searchParams.toString()}` |
|
) |
|
}, |
|
delete: (key: string) => { |
|
searchParams.delete(key) |
|
window.history.replaceState( |
|
null, |
|
'', |
|
`${window.location.pathname}?${searchParams.toString()}` |
|
) |
|
} |
|
} |
|
}
|
|
|