getCookie.tsx 483 B

12345678910111213
  1. export default function getCookie(name: string): string | null {
  2. if (document.cookie && document.cookie !== '') {
  3. const cookies = document.cookie.split(';');
  4. for (let i = 0; i < cookies.length; i++) {
  5. const cookie = cookies[i].trim();
  6. // Does this cookie string begin with the name we want?
  7. if (cookie.substring(0, name.length + 1) === name + '=') {
  8. return decodeURIComponent(cookie.substring(name.length + 1));
  9. }
  10. }
  11. }
  12. return null;
  13. }