리액트
react-cookie
5_hyun
2022. 9. 4. 16:30
반응형
react-cookie
react-cookie는 쿠키를 만들어 줄 수 있는 라이브러리이다.
-npm 사이트
https://www.npmjs.com/package/react-cookie
react-cookie
Universal cookies for React. Latest version: 4.1.1, last published: a year ago. Start using react-cookie in your project by running `npm i react-cookie`. There are 505 other projects in the npm registry using react-cookie.
www.npmjs.com
npm i react-cookie
이 명령어로 다운 받을 수 있다.
적용
-utills/cookie.ts
import { Cookies } from "react-cookie";
const cookies = new Cookies();
export const setCookie = (name: string, value: string, option?: any) => {
return cookies.set(name, value, { ...option });
};
export const getCookie = (name: string) => {
return cookies.get(name);
};
setCookie: 새로운 쿠키를 생성할 수 있다.
getCookie: 쿠키의 이름을 가져올 수 있다.
-logIn.tsx
setCookie("a", "123");
이렇게 하면 쿠키가 생성된다.
반응형