일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 타입 좁히기
- map
- dfs
- Promise
- tailwind
- 공변성
- CORS
- recoil
- SSR
- 결정 알고리즘
- ESlint
- 무한 스크롤
- app router
- TS
- 태그된 유니온
- RTK Query
- 호이스팅
- CI/CD
- useAppDispatch
- 투포인터
- webpack
- React
- 반공변성
- 리터럴 타입
- MSA
- Jest
- 인증/인가
- autosize
- async/await
- 인터섹션
Archives
- Today
- Total
짧은코딩
react-cookie 본문
반응형
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");
이렇게 하면 쿠키가 생성된다.
반응형
'리액트' 카테고리의 다른 글
React 일정 숫자만큼 화면에 쓰는법 (0) | 2022.09.21 |
---|---|
react-router 5버전에서 뒤로가기 버튼 만들기(useHistory) (0) | 2022.09.11 |
X-Requested-With (0) | 2022.09.03 |
form 안에서 sumbit이 아닌 버튼이 요청이 갈 때 해결법 (0) | 2022.09.02 |
Property 'checkIdModal' does not exist on type 'JSX.IntrinsicElements'. 해결법 (0) | 2022.09.01 |
Comments