Skip to content

Commit

Permalink
Merge pull request #2 from junction-asia-2023/feat/localstorage
Browse files Browse the repository at this point in the history
feat(utils): Add localstorage
  • Loading branch information
anyl92 authored Aug 19, 2023
2 parents bc12088 + 202a946 commit adcc0d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/no-explicit-any': 'off',
'import/order': [
'error',
{
Expand All @@ -29,4 +30,4 @@ module.exports = {
},
],
},
}
};
25 changes: 25 additions & 0 deletions src/features/shared/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export type STORAGE_KEY = 'user';

export const getItem = (item: STORAGE_KEY) => {
try {
const value = window.localStorage.getItem(item);
if (!value) {
return false;
}
const parsedValue = JSON.parse(value);
return parsedValue;
} catch (e) {
console.error(e);
return false;
}
};

export const setItem = (item: STORAGE_KEY, value: any) => {
try {
const stringValue = JSON.stringify(value);
window.localStorage.setItem(item, stringValue);
} catch (e) {
console.error(e);
return false;
}
};

0 comments on commit adcc0d6

Please sign in to comment.