Created
June 12, 2022 15:16
-
-
Save Avi-E-Koenig/add7e9cd12e0e40f5b07a2c02859ded2 to your computer and use it in GitHub Desktop.
basic ls stuff
This file contains hidden or 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
const ls = window?.localStorage; | |
export const save = (key, value) => { | |
try { | |
const payload = JSON.stringify({ [key]: value }) | |
ls.setItem(key, payload); | |
} catch (error) { | |
console.log("๐ ~ file: localstorage.js ~ line 5 ~ store ~ error", error) | |
} | |
} | |
export const get = (key) => { | |
try { | |
const storedEntry = JSON.parse(ls.getItem(key)) | |
return storedEntry?.[key] | |
} catch (error) { | |
console.log("๐ ~ file: localstorage.js ~ line 42 ~ get ~ error", error) | |
return null | |
} | |
} | |
export const remove = (key) => { | |
ls.removeItem(key) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment