-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 최근 상품 상세 페이지 로컬스토리지에 저장 * fix: 로그아웃 후 마이페이지 방문 시 에러 처리 * refactor: 로컬스토리지 로직 유틸로 이동
- Loading branch information
1 parent
3a950c2
commit 679ee07
Showing
6 changed files
with
68 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const getLocalStorage = (key: string) => { | ||
const item = localStorage.getItem(key); | ||
|
||
if (item) { | ||
try { | ||
return JSON.parse(item); | ||
} catch (error) { | ||
return item; | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export const setLocalStorage = (key: string, newValue: unknown) => { | ||
if (typeof newValue === 'string') { | ||
localStorage.setItem(key, newValue); | ||
return; | ||
} | ||
|
||
localStorage.setItem(key, JSON.stringify(newValue)); | ||
}; | ||
|
||
export const removeLocalStorage = (key: string) => { | ||
localStorage.removeItem(key); | ||
}; |