Skip to content

Instantly share code, notes, and snippets.

@Avi-E-Koenig
Created June 12, 2022 15:16
Show Gist options
  • Save Avi-E-Koenig/add7e9cd12e0e40f5b07a2c02859ded2 to your computer and use it in GitHub Desktop.
Save Avi-E-Koenig/add7e9cd12e0e40f5b07a2c02859ded2 to your computer and use it in GitHub Desktop.
basic ls stuff
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