Skip to content

Instantly share code, notes, and snippets.

@Juanpablobar
Created April 23, 2022 06:07
Show Gist options
  • Save Juanpablobar/c3269f1414a13f48c7953d1d1f5ab19d to your computer and use it in GitHub Desktop.
Save Juanpablobar/c3269f1414a13f48c7953d1d1f5ab19d to your computer and use it in GitHub Desktop.
JS: Set & Get localStorage
const setLocalStorage = () => {
if(typeof localStorage !== "undefined"){
try{
localStorage?.setItem("", JSON.stringify(data));
}catch(e){
console.error(e);
}
}
}
const localStorageData = []
const getLocalStorage = () => {
if(typeof localStorage !== "undefined"){
try{
localStorageData = JSON.parse(localStorage?.getItem('') || "[]");
}catch(error){
console.log("e-> ", error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment