Skip to content

Instantly share code, notes, and snippets.

@moharnadreza
Last active July 2, 2021 11:36
Show Gist options
  • Save moharnadreza/2745dcf9ccd64baf71fb9f40234d3eae to your computer and use it in GitHub Desktop.
Save moharnadreza/2745dcf9ccd64baf71fb9f40234d3eae to your computer and use it in GitHub Desktop.
Small utility function to get cookie by given key.
type Params = {
key: string;
}
export const getCookie = ({ key }: Params): string | null => {
const item = document.cookie.match("(^|;)\\s*" + key + "\\s*=\\s*([^;]+)");
return item?.pop() || null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment