0.1.0 • Published 4 years ago

@jeyz/cookie-manager v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Cookie Manager

This library enables easy cookie management in your React (TypeScript) application.

Usage

  1. 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);
  1. 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

Universal Cookie

0.1.0

4 years ago