Skip to content

Commit

Permalink
refactor local storage theme preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoSSC committed Jan 23, 2024
1 parent 5f1f67c commit bc3ed71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/common/local-storage/local-storage.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const retrieveValueFromLocalStorage = <T>(key: string): T | null => {
export const retrieveValueFromLocalStorage = (key: string) => {
const storedValue = localStorage.getItem(key);
return storedValue !== null ? JSON.parse(storedValue) : null;
return storedValue ? JSON.parse(storedValue) : null;
};

export const saveValueToLocalStorage = <T>(key: string, value: T): void => {
Expand Down
6 changes: 2 additions & 4 deletions src/core/providers/theme-provider/theme.business.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export const saveThemePreferenceToLocalStorage = (themeValue: string) => {

export const retrieveThemePreferenceFromLocalStorage = (): ThemeModel => {
try {
const themeMode = retrieveValueFromLocalStorage<'dark' | 'light'>(
'themeMode'
);
return themeMode !== null ? { themeMode } : createInitialTheme();
const themeMode = retrieveValueFromLocalStorage('themeMode');
return themeMode ? { themeMode } : createInitialTheme();
} catch {
return createInitialTheme();
}
Expand Down

0 comments on commit bc3ed71

Please sign in to comment.