Last active
June 9, 2023 18:24
-
-
Save djedr/4cfaa5ecd1e139e9111de8bbf03ca9a3 to your computer and use it in GitHub Desktop.
This file contains 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 smartQueryString = ((strs, ...params) => { | |
let ret = '' | |
for (let i = 0; i < strs.length - 1; ++i) { | |
const str = strs[i] | |
const param = params[i] | |
// or whatever escaping method is appropriate | |
ret += str + encodeURIComponent(param) | |
} | |
return ret | |
}) | |
const sqs = smartQueryString | |
// only thing changed now is sqs prepended to the string | |
fetch(sqs`/api/cities?country=${country}`) | |
.then(response => response.json()) | |
.then(json => { | |
if (!ignore) { | |
setCities(json); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment