-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace query-string
dependency with URLSearchParams
#336
Conversation
🦋 Changeset detectedLatest commit: 6cbbc72 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
const { themeName, code } = useParams((rawParams) => ({ | ||
themeName: | ||
typeof rawParams.themeName === 'string' ? rawParams.themeName : '', | ||
code: typeof rawParams.code === 'string' ? rawParams.code : '', | ||
})); | ||
const { themeName, code } = useParams((rawParams) => { | ||
const rawThemeName = rawParams.get('themeName'); | ||
const rawCode = rawParams.get('code'); | ||
|
||
return { | ||
themeName: rawThemeName || '', | ||
code: rawCode || '', | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query-string
's API returned a single value or an array, but URLSearchParams
' .get
API returns string | null
, so there's no need for a typeof
check here anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what about my 8 year old Samsung phone that I refuse to update since I first bought it?
try { | ||
return queryString.parse( | ||
return new URLSearchParams( | ||
playroomConfig.paramType === 'hash' | ||
? location.hash.replace(/^#/, '') | ||
: location.search | ||
); | ||
} catch (err) { | ||
return {}; | ||
return new URLSearchParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This try catch
might not even be needed anymore since AFAICT URLSearchParams constructor never throws. I couldn't make it throw on any input, and a cursory glance at the spec didn't mention throwing. But probably better to be safe than sorry.
The platform-native
URLSearchParams
has broad browser support, so we don't really have a need forquery-string
anymore.