Skip to content

Commit

Permalink
fix: restore React Native compatibility (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Aug 8, 2023
1 parent 05335e1 commit dd1cb97
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/data/encodeQueryString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ export const encodeQueryString = ({
const searchParams = new URLSearchParams()
// We generally want tag at the start of the query string
const {tag, ...opts} = options
if (tag) searchParams.set('tag', tag)
searchParams.set('query', query)
// We're using `append` instead of `set` to support React Native: https://github.com/facebook/react-native/blob/1982c4722fcc51aa87e34cf562672ee4aff540f1/packages/react-native/Libraries/Blob/URL.js#L86-L88
if (tag) searchParams.append('tag', tag)
searchParams.append('query', query)

// Iterate params, the keys are prefixed with `$` and their values JSON stringified
for (const [key, value] of Object.entries(params)) {
searchParams.set(`$${key}`, JSON.stringify(value))
searchParams.append(`$${key}`, JSON.stringify(value))
}
// Options are passed as-is
for (const [key, value] of Object.entries(opts)) {
// Skip falsy values
if (value) searchParams.set(key, `${value}`)
if (value) searchParams.append(key, `${value}`)
}

return `?${searchParams}`
Expand Down

0 comments on commit dd1cb97

Please sign in to comment.