e81e8a8f71
* Revert "Revert "Merge branch 'main' of https://github.com/Uniswap/interface" (#2912)" This reverts commit 7d343dcfbdf75a2f91d28cefce84e4b1bace7b87. * Revert "deleted files" This reverts commit 097b8361d4c09afd3cb681c4622145c555ced884.
18 lines
606 B
TypeScript
18 lines
606 B
TypeScript
import { parse, ParsedQs } from 'qs'
|
|
import { useMemo } from 'react'
|
|
import { useLocation } from 'react-router-dom'
|
|
|
|
export function parsedQueryString(search?: string): ParsedQs {
|
|
if (!search) {
|
|
// react-router-dom places search string in the hash
|
|
const hash = window.location.hash
|
|
search = hash.substr(hash.indexOf('?'))
|
|
}
|
|
return search && search.length > 1 ? parse(search, { parseArrays: false, ignoreQueryPrefix: true }) : {}
|
|
}
|
|
|
|
export default function useParsedQueryString(): ParsedQs {
|
|
const { search } = useLocation()
|
|
return useMemo(() => parsedQueryString(search), [search])
|
|
}
|