Created
June 20, 2023 18:30
-
-
Save leomartinsdev/52cc856eb5165fb9be6860afb188f309 to your computer and use it in GitHub Desktop.
Generic localStorage function to use in your services folder.
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
export function saveItem(key, value) { | |
if (typeof value === 'string') { | |
localStorage.setItem(key, value); | |
} else { | |
localStorage.setItem(key, JSON.stringify(value)); | |
} | |
} | |
export function getItem(key) { | |
const storedValue = localStorage.getItem(key); | |
return storedValue ? JSON.parse(storedValue) : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment