recoil-persist
: Recoil Atom으로 state를 이용하는 app에서 자동으로 Storage에 state를 저장할 수 있다.
install
npm install recoil-persist
atom.ts파일에서 recoilPersist import 후, 저장할 storage 및 key 정의
// atom.ts
import { recoilPersist } from "recoil-persist";
const { persistAtom } = recoilPersist({
key: "trelloBoardLocal", // 중복되지 않도록 주의
storage: localStorage,
});
*storage에 저장 되는 key값이 중복되지 않도록 주의
effects_UNSTABLE 추가// atom.ts
export const ToggleThemeAtom = atom<boolean>({
key: "toggleTheme",
default: true,
effects_UNSTABLE: [persistAtom],
});
키 : trelloBoardLocal
값 : {"toggleTheme":false}