-
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.
Merge pull request #41 from capstone-maru/fix/persist-effect
fix: 상태 관련 로직 정리
- Loading branch information
Showing
9 changed files
with
52 additions
and
56 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
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 |
---|---|---|
@@ -1,38 +1,34 @@ | ||
export type StorageType = 'session' | 'local'; | ||
|
||
export const save = ({ | ||
export const save = <T>({ | ||
type, | ||
key, | ||
value, | ||
}: { | ||
type: StorageType; | ||
key: string; | ||
value: string; | ||
value: T; | ||
}) => { | ||
if (typeof window === 'undefined') return; | ||
|
||
if (type === 'local') { | ||
localStorage.setItem(key, value); | ||
} else { | ||
sessionStorage.setItem(key, value); | ||
} | ||
const storage = type === 'local' ? localStorage : sessionStorage; | ||
storage.setItem(key, JSON.stringify(value)); | ||
}; | ||
|
||
export const load = ({ type, key }: { type: StorageType; key: string }) => { | ||
export const load = <T>({ type, key }: { type: StorageType; key: string }) => { | ||
if (typeof window === 'undefined') return null; | ||
|
||
if (type === 'local') { | ||
return localStorage.getItem(key); | ||
} | ||
return sessionStorage.getItem(key); | ||
const storage = type === 'local' ? localStorage : sessionStorage; | ||
const storedValue = storage.getItem(key); | ||
if (storedValue === null) return null; | ||
|
||
const parsedValue = JSON.parse(storedValue) as T; | ||
return parsedValue; | ||
}; | ||
|
||
export const remove = ({ type, key }: { type: StorageType; key: string }) => { | ||
if (typeof window === 'undefined') return; | ||
|
||
if (type === 'local') { | ||
localStorage.removeItem(key); | ||
} else { | ||
sessionStorage.removeItem(key); | ||
} | ||
const storage = type === 'local' ? localStorage : sessionStorage; | ||
storage.removeItem(key); | ||
}; |