From 98adcd75e25b3482a05e78d23576a314b525fc0c Mon Sep 17 00:00:00 2001 From: cruelladevil Date: Mon, 15 May 2023 12:44:01 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EA=B8=B0=EB=B3=B8=EA=B0=92=20=EB=B0=8F=20localStor?= =?UTF-8?q?age=20=EC=9C=A0=ED=8B=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/atoms/cart.ts | 6 +++--- src/utils/localStorage.ts | 9 --------- 2 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 src/utils/localStorage.ts diff --git a/src/atoms/cart.ts b/src/atoms/cart.ts index d4ea7f7417..da219647af 100644 --- a/src/atoms/cart.ts +++ b/src/atoms/cart.ts @@ -1,12 +1,12 @@ import { AtomEffect, atom, selector } from 'recoil'; import { Cart } from '../types/cart'; -import { getLocalData } from '../utils/localStorage'; const localStorageEffect: (key: string) => AtomEffect = (key: string) => ({ setSelf, onSet }) => { const savedValue = localStorage.getItem(key); - if (savedValue != null) { + + if (savedValue !== null) { setSelf(JSON.parse(savedValue)); } @@ -17,7 +17,7 @@ const localStorageEffect: (key: string) => AtomEffect = export const cartState = atom({ key: 'CartListState', - default: getLocalData('CART'), + default: [], effects: [localStorageEffect('CART')], }); diff --git a/src/utils/localStorage.ts b/src/utils/localStorage.ts deleted file mode 100644 index 1f3a2f86bc..0000000000 --- a/src/utils/localStorage.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const getLocalData = (key: string) => { - const data = localStorage.getItem(key); - if (!data) return []; - return JSON.parse(data); -}; - -export const setLocalData = (key: string, newData: object) => { - localStorage.setItem(key, JSON.stringify(newData)); -};