import { atom } from 'recoil';
import { recoilPersist } from 'recoil-persist';
import { PostLoginBody, UserData } from '../types/user';
// ✨ 페이지가 변경되더라도 상태관리를 유지
const { persistAtom } = recoilPersist();
export const userInfoState = atom<PostLoginBody>({
// ✅ 내부적으로 atom을 식별하는데 사용되는 고유한 문자
key: 'userInfo',
// ✅ atom의 초깃값 또는 Promise 또는 동일한 타입의 값을 나타내는 다른 atom이나 selector.
default: {
snsId: 'nori@naver.com',
provider: 'naver',
email: 'nori@naver.com',
},
effects_UNSTABLE: [persistAtom],
});
📄 pages/login.tsx
사용 방법
useRecoilState 👉 atom에서 정의한 전역상태( 여기서는 userInfoState)를 state처럼 관리
🔥 Related Issues
🎡 작업 내용
✅ PR Point
📄 core/atom.ts
전역 저장소를 만드는 공간이라고 생각하면 될 것 같아요 !
📄 pages/login.tsx
사용 방법
useResetRecoilState 👉 atom에서 정의한 전역상태 초기화
👀 스크린샷 / GIF / 링크
https://user-images.githubusercontent.com/79238676/179336365-0ccadd88-bd3d-4a0c-a89c-5a7aeed2d292.mov
📚 Reference