Created
April 23, 2022 06:07
-
-
Save Juanpablobar/c3269f1414a13f48c7953d1d1f5ab19d to your computer and use it in GitHub Desktop.
JS: Set & Get localStorage
This file contains 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 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