0.1.0 • Published 4 years ago
@jeyz/cookie-manager v0.1.0
Cookie Manager
This library enables easy cookie management in your React (TypeScript) application.
Usage
- Declare
CookieManager
for a specific cookie name:
import { Cookie } from '@jeyz/cookie-manager';
export enum ApplicationCookieNames {
sessionCookie = 'my-app-session-cookie'
}
// usage with TypeScript
export interface SessionCookieType {
accessToken?: string;
refreshToken?: string;
}
export const SessionCookie = new Cookie<SessionCookieType>(sessionCookie);
- Access your cookie via
useCookie
hook:
import { useCookie } from '@jeyz/cookie-manager';
import { SessionCookie } from 'MyCookies.ts';
const App = () => {
const session = useCookie(SessionCookie);
useEffect(() => {
if (isUserSignedIn()) {
session.set({ accessToken: '123' });
} else {
session.remove();
}
});
// ...
return `Your access token: ${session.getCookie()}`;
}
Developed using
0.1.0
4 years ago