Skip to content

Instantly share code, notes, and snippets.

@ats1999
Created September 19, 2021 17:08
Show Gist options
  • Save ats1999/877f00d4618f091e606bd77fd0a58f8c to your computer and use it in GitHub Desktop.
Save ats1999/877f00d4618f091e606bd77fd0a58f8c to your computer and use it in GitHub Desktop.
// get item from local storage
export const getLocalStorage = (str)=>{
try {
return localStorage.getItem(str);
} catch (error) {
// cookie is blocked
return false;
}
}
// set item into localstorage
export const setLocalStorage = (str,val)=>{
try {
localStorage.setItem(str,val);
return true;
} catch (error) {
// cookie is blocked
return false;
}
}
// check if cookie is enabled
export const isCookie=()=>{
try {
return Boolean(localStorage);
} catch (error) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment