Gets the value of a cookie by name. If the value is a valid JSON string, it will be automatically parsed.
The name of the cookie to retrieve
The cookie value (parsed if JSON), or null if the cookie doesn't exist
// Get string cookieconst userToken = getCookie<string>('token');if (userToken) { console.log('Token:', userToken);}// Get object cookieconst userData = getCookie<{ id: number; name: string }>('userData');if (userData) { console.log('User:', userData.name);} Copy
// Get string cookieconst userToken = getCookie<string>('token');if (userToken) { console.log('Token:', userToken);}// Get object cookieconst userData = getCookie<{ id: number; name: string }>('userData');if (userData) { console.log('User:', userData.name);}
Gets the value of a cookie by name. If the value is a valid JSON string, it will be automatically parsed.