Skip to content

Instantly share code, notes, and snippets.

@nsrCodes
Created February 9, 2021 14:42
Show Gist options
  • Save nsrCodes/f9b95c69c08a28cfc7ed55cb2975966f to your computer and use it in GitHub Desktop.
Save nsrCodes/f9b95c69c08a28cfc7ed55cb2975966f to your computer and use it in GitHub Desktop.
General Utils
import { toast } from "react-toastify";
const copyToClipBoard = (textToCopy, prompt) => {
prompt = prompt || "Copied to clipboard!"
navigator.clipboard.writeText(textToCopy)
.then(() => {
toast.info(prompt)
}, (err) => {
console.error('Could not copy text: ', err);
});
}
function getQueryParamsAsMap() {
let queryParams={};
var params = new URLSearchParams(window.location.search);
params.forEach((value, key) => {queryParams[key] = value})
return queryParams
}
@nsrCodes
Copy link
Author

nsrCodes commented Mar 2, 2021

In case of query params with no value, eg: example.com/?code, the queryParams will be {"": "code"}
This means it isn't a query param with no value but rather a query param with no key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment