Last active
September 18, 2021 05:26
-
-
Save danieljpgo/c13e7d44454b643e3aafc82b1a3c1b15 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Returns the current object from local storage associated with the given key. | |
| * @template T | |
| * @param {String} key The key to set in localStorage for this value | |
| * @returns {T|undefined} | |
| */ | |
| export function getLocalStorageData(key) { | |
| const data = window.localStorage.getItem(key); | |
| try { | |
| return data ? JSON.parse(data) : undefined; | |
| } catch { | |
| return undefined; | |
| } | |
| } | |
| /** | |
| * Save the value to local storage associated with the given key. | |
| * @template T | |
| * @param {String} key The key to set in localStorage for this value | |
| * @param {T} body The key to set in localStorage for this value | |
| */ | |
| export function setLocalStorageData(key, body) { | |
| window.localStorage.setItem(key, JSON.stringify(body)); | |
| } | |
| /** | |
| * Remove the value from local storage associated with the given key. | |
| * @param {String} key The key to set in localStorage for this value | |
| */ | |
| export function removeLocalStorageData(key) { | |
| window.localStorage.removeItem(key); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment